mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 17:07:22 +00:00
docs: add some info on typescript usage (#1020)
This commit is contained in:
parent
0b45721b8e
commit
380fd66f67
@ -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`.
|
||||
|
13
docs/content/2.concepts/3.typescript.md
Normal file
13
docs/content/2.concepts/3.typescript.md
Normal 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.
|
||||
::
|
15
docs/content/3.docs/2.directory-structure/17.tsconfig.md
Normal file
15
docs/content/3.docs/2.directory-structure/17.tsconfig.md
Normal 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`.
|
Loading…
Reference in New Issue
Block a user