generated from orta/TypeScript-TSServer-Plugin-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,86 @@ | ||
# Adonis Typescript Plugin | ||
|
||
A Typescript plugin for additional type-checking in Adonis projects. | ||
|
||
# Setup | ||
|
||
1. Install the plugin as a dev dependency | ||
|
||
``` | ||
npm i -D adonis-ts-plugin | ||
``` | ||
|
||
2. Add the plugin to your `tsconfig.json` | ||
|
||
```json | ||
{ | ||
"compilerOptions": { | ||
/* ... */ | ||
"plugins": [ | ||
{ | ||
"name": "adonis-ts-plugin" | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
3. if you are using VSCode, configure it to use the Typescript version from `node_modules` by adding the following to the project settings: | ||
|
||
```json | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} | ||
``` | ||
|
||
# Features | ||
|
||
## `router.resource` type-checking | ||
|
||
This plugin improves the type-checking of the `router.resource` method. | ||
|
||
Without the plugin, the following code doesn't show any errors: | ||
```ts | ||
import router from '@adonisjs/core/services/router' | ||
|
||
class TestController {} | ||
|
||
router.resource('test', TestController) // <- TS does not complain | ||
``` | ||
|
||
With the plugin, the same code will show the following error on the `router.resource` call: | ||
``` | ||
The following methods are missing on the controller: index, create, store, show, edit, update, destroy | ||
``` | ||
|
||
# Command line tool | ||
|
||
This plugin comes with a command-line tool that can be used to show the additional type errors (because the default `tsc` does not include the diagnostics from plugins). | ||
|
||
To check the whole project use | ||
``` | ||
npx adonis-ts-plugin check | ||
``` | ||
|
||
You can also check only one or multiple files by providing them in the arguments: | ||
``` | ||
npx adonis-ts-plugin check src/path/to/file1.ts src/path/to/file2.ts | ||
``` | ||
|
||
if you want the command to print the errors as a JSON array, use the `--json` flag: | ||
``` | ||
npx adonis-ts-plugin check --json src/path/to/file1.ts src/path/to/file2.ts | ||
``` | ||
|
||
The resulting JSON is something like the following | ||
```json | ||
[ | ||
{ | ||
"start": [5, 1], | ||
"end": [5, 40], | ||
"category": 1, | ||
"code": 99001, | ||
"message": "The following methods are missing on the controller: index, create, store, show, edit, update, destroy" | ||
} | ||
] | ||
``` |