Firstly, add decapi
and it's peer dependecies to your project
Important! To work with typescript
, you'll need reflect-metadata
so decapi
can infer types from your code.
Add import "reflect-metadata";
somewhere in bootstrap (before any decapi
decorator is used) of your app eg app/index.ts
.
tsconfig.json
decapi
will try to infer types of your fields, when possible. To allow this, you'll have to add following to your tsconfig.json
compilerOptions
section:
Also you need to target es6
or newer target in your compilerOptions
.
Important! es5
target will not work correctly. ObjectTypes type inference only currently works for es6 or newr targets.
In order to run the rtti transformer, you need to compile using ttypescript
.
When you develop, you can use ts-node
programmatically:
or you can invoke it like this:
For production, it's best to compile using ttsc
instead of tsc
.
There's also good reference on ttypescript
here: https://github.com/cevek/ttypescript/blob/master/README.md
decapi
work without typescript?No we rely on typescript for type inference.