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