@formidablejs/ts-ports v0.4.6
ts-ports
ts-ports enables TypeScript support in the Formidable framework.
Requirements
- @formidablejs/framework:
>=0.12.x
Install
Recommended
formidable new <app-name> [...args] --tsExisting Project
npm:
npm i @formidablejs/ts-ports --saveyarn:
yarn add @formidablejs/ts-ports --saveConfiguration
Open 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,
...Usage
@use Decorator
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.");
}
}Commands
ts-ports also adds 2 new commands to your application.
make:interface
node craftsman make:interface IUserControllermake:type
node craftsman make:type Usertypes:generate
node craftsman types:generateThis will generate types based on the rules of your requests.
Works with TypeScript only
Security
If you discover any security related issues, please email donaldpakkies@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.