ts-ports enables TypeScript support in the Formidable framework.
- @formidablejs/framework:
>=0.12.x
formidable new <app-name> [...args] --tsnpm:
npm i @formidablejs/ts-ports --saveyarn:
yarn add @formidablejs/ts-ports --saveOpen the package.json file and add "language": "TypeScript":
{
...
"language": "TypeScript",
...
}Finaly, open the config/app.ts config file and add TypeScriptPortsServiceResolver under resolvers:
...
import { TypeScriptPortsServiceResolver } from '@formidablejs/ts-ports';
export default {
...
resolvers: {
...,
TypeScriptPortsServiceResolver,
...The use decorator in @formidablejs/ts-ports works the same way as the use decorator in @formidablejs/framework. To get started, just import the use decorator from @formidablejs/ts-ports and add it next to any of your class functions:
import { use } from "@formidablejs/ts-ports";
import { Controller } from "./Controller";
export class UserController extends Controller {
@use("table:users")
public async show(user: Promise<User | null>): Promise<User | void> {
return (await user) || this.notFound("User not found.");
}
}ts-ports also adds 2 new commands to your application.
node craftsman make:interface IUserControllernode craftsman make:type Usernode craftsman types:generateThis will generate types based on the rules of your requests.
Works with TypeScript only
If you discover any security related issues, please email donaldpakkies@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.