Skip to main content

TypeScript Support

Overview​

ReSolve is written in TypeScript and its packages export type declarations for all building blocks of a reSolve application. This article describes how to develop a reSolve application with TypeScript and lists types that you need to use in the application code.

Creating a TypeScript Application​

All template and example projects are available both in JavaScript and TypeScript variations. When you use the create-resolve-app tool, add the -t flag to the command input to specify that a TypeScript application should be created:

yarn create resolve-app hello-world-react -e react -t

Developing With reSolve Types​

When you develop a reSolve application with TypeScript, you need to assign correct types to all of the application's building blocks (aggregates, read model projections and resolvers, sagas, and so on). Refer to the resources listed below for information on the type scheme that you should follow:

  • The Type Correspondence Tables list the available types in a single document section.
  • All TypeScript example and template projects are correctly typed and can be used for reference.
  • The API Reference articles contain information on the types associated with the described API members.

Example​

The code below demonstrates a correctly typed read model implementation:

import { ReadModel } from '@resolve-js/core'
import { ResolveStore } from '@resolve-js/readmodel-base'
...

const projection: ReadModel<ResolveStore> = {
Init: async (store) => {
await store.defineTable('ShoppingLists', {
indexes: {
id: 'string',
},
fields: ['createdAt', 'name'],
})
},

[SHOPPING_LIST_CREATED]: async (
store,
{ aggregateId, timestamp, payload: { name } }
) => {
const shoppingList = {
id: aggregateId,
name,
createdAt: timestamp,
}

await store.insert('ShoppingLists', shoppingList)
},
...
}
export default projection

For more information on the types used in the above code sample, refer to the following API reference articles:

Type Correspondence Tables​

The tables below list the available TypeScript types and the packages that export these types.

Write Side​

ObjectTypePackage
Aggregate Command HandlersAggregate@resolve-js/core
Aggregate ProjectionAggregateProjection@resolve-js/core
CommandCommand@resolve-js/core
EventEvent@resolve-js/core

Read Side​

Read Models​

ObjectTypePackage
ProjectionReadModel@resolve-js/core
ResolversReadModelResolvers@resolve-js/core
ResolverReadModelResolver@resolve-js/core
StoreResolveStore@resolve-js/readmodel-base
QueryReadModelQuery@resolve-js/core
Query ResultReadModelQueryResult@resolve-js/core

View Models​

ObjectTypePackage
View Model ProjectionViewModelProjection@resolve-js/core
Read Model ResolversViewModelResolver@resolve-js/core
QueryViewModelQuery@resolve-js/core
Query ResultViewModelQueryResult@resolve-js/core

Saga​

ObjectTypePackage
SagaSaga@resolve-js/core

Middleware​

ObjectTypePackage
Command MiddlewareCommandMiddleware@resolve-js/core
Read Model Projection MiddlewareReadModelProjectionMiddleware@resolve-js/core
Read Model Resolver MiddlewareReadModelResolverMiddleware@resolve-js/core

API Handlers​

ObjectTypePackage
RequestResolveRequest@resolve-js/runtime-base
ResponseResolveResponse@resolve-js/runtime-base
ContextUserBackendResolve@resolve-js/runtime-base

Monitoring​

ObjectTypePackage
MetricMonitoringMetric@resolve-js/core
Custom MetricMonitoringCustomMetric@resolve-js/core
AdapterMonitoringAdapter@resolve-js/core
Monitoring ObjectMonitoring@resolve-js/core