id | title |
---|---|
typescript-support |
TypeScript Support |
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
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.
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
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.
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
import { ReadModelResolvers } from '@resolve-js/core'
import { ResolveStore } from '@resolve-js/readmodel-base'
const resolvers: ReadModelResolvers<ResolveStore> = {
all: async (store) => {
return await store.find('ShoppingLists', {}, null, { createdAt: 1 })
},
}
export default resolvers
For more information on the types used in the above code sample, refer to the following API reference articles:
The tables below list the available TypeScript types and the packages that export these types.
Object | Type | Package |
---|---|---|
Aggregate Command Handlers | Aggregate |
@resolve-js/core |
Aggregate Projection | AggregateProjection |
@resolve-js/core |
Command | Command |
@resolve-js/core |
Event | Event |
@resolve-js/core |
Object | Type | Package |
---|---|---|
Projection | ReadModel |
@resolve-js/core |
Resolvers | ReadModelResolvers |
@resolve-js/core |
Resolver | ReadModelResolver |
@resolve-js/core |
Store | ResolveStore |
@resolve-js/readmodel-base |
Query | ReadModelQuery |
@resolve-js/core |
Query Result | ReadModelQueryResult |
@resolve-js/core |
Object | Type | Package |
---|---|---|
View Model Projection | ViewModelProjection |
@resolve-js/core |
Read Model Resolvers | ViewModelResolver |
@resolve-js/core |
Query | ViewModelQuery |
@resolve-js/core |
Query Result | ViewModelQueryResult |
@resolve-js/core |
Object | Type | Package |
---|---|---|
Saga | Saga |
@resolve-js/core |
Object | Type | Package |
---|---|---|
Command Middleware | CommandMiddleware |
@resolve-js/core |
Read Model Projection Middleware | ReadModelProjectionMiddleware |
@resolve-js/core |
Read Model Resolver Middleware | ReadModelResolverMiddleware |
@resolve-js/core |
Object | Type | Package |
---|---|---|
Request | ResolveRequest |
@resolve-js/runtime-base |
Response | ResolveResponse |
@resolve-js/runtime-base |
Context | UserBackendResolve |
@resolve-js/runtime-base |
Object | Type | Package |
---|---|---|
Metric | MonitoringMetric |
@resolve-js/core |
Custom Metric | MonitoringCustomMetric |
@resolve-js/core |
Adapter | MonitoringAdapter |
@resolve-js/core |
Monitoring Object | Monitoring |
@resolve-js/core |