docs: add some info on typescript usage (#1020)

This commit is contained in:
Daniel Roe 2021-10-14 12:38:36 +01:00 committed by GitHub
parent 0b45721b8e
commit 380fd66f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View File

@ -40,6 +40,12 @@ Nitro allows 'direct' calling of routes via the globally-available `$fetch` help
For more information on `$fetch` features, check out [ohmyfetch](https://github.com/unjs/ohmyfetch).
## Typed API routes
When using API routes (or middleware), Nitro will generate typings for these routes as long as you are returning a value instead of using `res.end()` to send a response.
You can access these types when using `$fetch()` or `useFetch()`.
## Standalone Server
Nitro produces a standalone server dist that is independent of `node_modules`.

View File

@ -0,0 +1,13 @@
# TypeScript
Nuxt 3 is fully typed and provides helpful shortcuts to ensure you have access to accurate type information when you are coding.
## Auto-generated types
When you run `nuxi dev` or `nuxi build`, a `nuxt.d.ts` file will be auto-generated at the root of your project with the types of any modules you are using, as well as the key types that Nuxt 3 requires. Your IDE should recognise these types automatically. It is your choice whether to commit it to version control, but you shouldn't need to do so.
Some of the references in the file are to files that are generated within your `buildDir` (`.nuxt`) and therefore for full typings, you will need to run `nuxi dev` to generate the directory.
::alert{icon=👉}
Nitro also [auto-generates types](/concepts/server-engine#typed-api-routes) for API routes.
::

View File

@ -0,0 +1,15 @@
---
icon: IconFile
title: tsconfig.json
head.title: TypeScript configuration file
---
Nuxt automatically generates a `.nuxt/tsconfig.json` file with the resolved aliases you are using in your Nuxt project, as well as with other sensible defaults. You can benefit from this by creating a `tsconfig.json` in the root of your project with the following content:
```json
{
"extends": "./.nuxt/tsconfig.json"
}
```
As you need to, you can customize the contents of this file. However, note that if you need to customize your `paths`, this will completely override the auto-generated path aliases. Instead, it is suggested that you add any path aliases you need to the `alias` property within your `nuxt.config`, where they will get picked up and added to the autogenerated `tsconfig`.