https://github.com/formidablejs/ts-ports
Enable TypeScript support in the Formidable Framework.
https://github.com/formidablejs/ts-ports
typescript
Last synced: 3 days ago
JSON representation
Enable TypeScript support in the Formidable Framework.
- Host: GitHub
- URL: https://github.com/formidablejs/ts-ports
- Owner: formidablejs
- License: mit
- Created: 2022-07-23T10:41:47.000Z (over 3 years ago)
- Default Branch: dev
- Last Pushed: 2025-04-20T14:30:00.000Z (10 months ago)
- Last Synced: 2025-10-08T15:18:51.124Z (4 months ago)
- Topics: typescript
- Language: TypeScript
- Homepage: https://formidablejs.org/docs/typescript-support
- Size: 520 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-ports
`ts-ports` enables TypeScript support in the Formidable framework.



## Requirements
- [@formidablejs/framework](https://www.npmjs.com/package/@formidablejs/framework): `>=0.12.x`
## Install
### Recommended
```bash
formidable new [...args] --ts
```
### Existing Project
npm:
```bash
npm i @formidablejs/ts-ports --save
```
yarn:
```bash
yarn add @formidablejs/ts-ports --save
```
## Configuration
Open the `package.json` file and add `"language": "TypeScript"`:
```json
{
...
"language": "TypeScript",
...
}
```
Finaly, open the `config/app.ts` config file and add `TypeScriptPortsServiceResolver` under resolvers:
```ts
...
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:
```ts
import { use } from "@formidablejs/ts-ports";
import { Controller } from "./Controller";
export class UserController extends Controller {
@use("table:users")
public async show(user: Promise): Promise {
return (await user) || this.notFound("User not found.");
}
}
```
### Commands
`ts-ports` also adds 2 new commands to your application.
#### `make:interface`
```bash
node craftsman make:interface IUserController
```
#### `make:type`
```bash
node craftsman make:type User
```
#### `types:generate`
```bash
node craftsman types:generate
```
This 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](LICENSE) for more information.