Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/guide/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,25 @@ All you need to do is update your **package.json** file:
:::

You can now use TypeScript for **nuxt.config** file, local **modules** and **serverMiddlewares**.

::: warning

`@nuxt/typescript-runtime` does not support programmatic usage (as it extends `@nuxt/cli`).

Advanced users might try adding the following code to your server entrypoint (see [source](https://github.com/nuxt/typescript/blob/master/packages/typescript-runtime/src/index.ts)):

```js
import { register } from 'ts-node'

register({
project: 'tsconfig.json',
compilerOptions: {
module: 'commonjs'
}
})
```

However, this is **not recommended or supported**.
:::


16 changes: 16 additions & 0 deletions docs/guide/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ and create a **`tsconfig.json`** file :
Check official [TypeScript documentation](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to learn about the different compiler options.
:::

::: warning

If you are using Nuxt programmatically with a custom server framework, note that you will need to ensure that you wait for Nuxt to be ready before building:

```js

// Make sure to wait for Nuxt to load @nuxt/typescript-build before proceeding
await nuxt.ready()
...
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
}
```
:::

That's it, you're all set to use TypeScript in your **layouts**, **components**, **plugins** and **middlewares**.

You can check the [**CookBook**](../cookbook/components/) section to get some TypeScript recipes for your Nuxt project.
Expand Down