-
Notifications
You must be signed in to change notification settings - Fork 9
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
6 changed files
with
71 additions
and
12 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
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# TypeScript | ||
|
||
This binding introduces support for routes written in TypeScript. | ||
|
||
## Install | ||
|
||
`npm install @primate/binding @swc/core@1.3` | ||
|
||
## Configure | ||
|
||
Import and initialize the module in your configuration. | ||
|
||
```js caption=primate.config.js | ||
import { typescript } from "@primate/binding"; | ||
|
||
export default { | ||
modules: [ | ||
typescript(), | ||
], | ||
}; | ||
``` | ||
|
||
## Use | ||
|
||
Using TypeScript is identical to using JavaScript, with the exception that to | ||
get proper editor completions for your route function parameters and return | ||
code, your route needs to use `satisfies Route` with the Primate `Route` export. | ||
|
||
```ts caption=routes/plain-text.ts | ||
import { Route } from "primate"; | ||
|
||
export default { | ||
get() { | ||
return "Donald"; | ||
}, | ||
} satisfies Route; | ||
``` | ||
|
||
!!! | ||
Using `satisfies Route` is optional and will only result in your editor showing | ||
your proper completions. | ||
!!! | ||
|
||
Refer to the [routes] and [responses] documentation for the different aspects | ||
of handling requests and returning responses. | ||
|
||
## Configuration options | ||
|
||
### extension | ||
|
||
Default `".ts"` | ||
|
||
The file extension associated with TypeScript routes. | ||
|
||
[routes]: /guide/routes | ||
[responses]: /guide/responses |
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
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
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