Tired of hand-typing types for NestJS CQRS package? We got you covered!
All features provided by @nestjs-architects/typed-cqrs
are now available natively in @nestjs/cqrs starting from NestJS 11.
This library will no longer be maintained or developed, but it will still work with NestJS@11 and old versions.
Migrating to @nestjs/cqrs
is simple:
- Replace imports from
@nestjs-architects/typed-cqrs
to@nestjs/cqrs
. - Drop
Inferred
fromIInferredQueryHandler
andIInferredCommandHandler
–IQueryHandler
andICommandHandler
now support its extensions. - Command, Query, CommandResult, and QueryResult are already included in @nestjs/cqrs.
- A quick find & replace in your codebase is all you need!
First install base @nestjs/cqrs
package.
$ npm i @nestjs/cqrs
All you need to do, is to extend your query with type of expected response.
import { Query } from '@nestjs-architects/typed-cqrs';
export class GetProfileQuery extends Query<ResultType> {}
Now, when implementing handler, you get all type completion & safety!
import { IInferredQueryHandler, QueryHandler } from '@nestjs/cqrs';
@QueryHandler(GetProfileQuery)
export class GetProfileHandler implements IInferredQueryHandler<GetProfileQuery> {}