orbit-type-generator
TypeScript type generator for Orbit schema definitions.
API
const definition = models: user: attributes: username: type: 'string' const schema = definitionconst types =
The types
variable now contains this code:
;;
CLI
If you have a file schema.js
:
models: user: attributes: username: type: 'string'
you can generate the types with:
orbit-type-generator schema.js > models.d.ts
Advanced
Using TypeScript types
You can type attributes using TypeScript types or interfaces.
The generator will automatically import the type based on a resolved
tsconfig.json
in the directory you're executing from.
const definition = models: user: attributes: permission: type: 'UserPermission'
You can optionally specify a fallback type to use if TypeScript can't resolve the specified type:
const definition = models: user: attributes: permission: type: 'string' ts: 'UserPermission' const schema = definitionconst types =
Specify a different base directory
If you want your imports to be relative to a different directory than the directory you're executing from, use:
const types =
Todo
- Properly generate types for relationships
- Support .ts files in CLI using on-the-fly compiling