Skip to content

Commit 22caab8

Browse files
authored
docs: improve TypeScript navigation/discoverability (#86938)
Add signposts and info about next-env.d.ts. Also rework links from getting started to TypeScript features, and from the to config reference.
1 parent b90b303 commit 22caab8

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

docs/01-app/01-getting-started/01-installation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ You can enable the plugin in VS Code by:
330330

331331
</AppOnly>
332332

333-
See the [TypeScript reference](/docs/app/api-reference/config/next-config-js/typescript) page for more information.
333+
See the [TypeScript reference](/docs/app/api-reference/config/typescript) page for more information.
334334

335335
## Set up linting
336336

docs/01-app/01-getting-started/02-project-structure.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Top-level files are used to configure your application, manage dependencies, run
4444
| [`.env.development`](/docs/app/guides/environment-variables) | Development environment variables (should not be tracked by version control) |
4545
| [`eslint.config.mjs`](/docs/app/api-reference/config/eslint) | Configuration file for ESLint |
4646
| `.gitignore` | Git files and folders to ignore |
47-
| `next-env.d.ts` | TypeScript declaration file for Next.js (should not be tracked by version control) |
47+
| [`next-env.d.ts`](/docs/app/api-reference/config/typescript#next-envdts) | TypeScript declaration file for Next.js (should not be tracked by version control) |
4848
| `tsconfig.json` | Configuration file for TypeScript |
4949
| `jsconfig.json` | Configuration file for JavaScript |
5050

docs/01-app/03-api-reference/05-config/01-next-config-js/typescript.mdx

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
---
22
title: typescript
3-
description: Next.js reports TypeScript errors by default. Learn to opt-out of this behavior here.
3+
description: Configure how Next.js handles TypeScript errors during production builds and specify a custom tsconfig file.
44
---
55

66
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
77

8+
Configure TypeScript behavior with the `typescript` option in `next.config.js`:
9+
10+
```js filename="next.config.js"
11+
module.exports = {
12+
typescript: {
13+
ignoreBuildErrors: false,
14+
tsconfigPath: 'tsconfig.json',
15+
},
16+
}
17+
```
18+
19+
## Options
20+
21+
| Option | Type | Default | Description |
22+
| ------------------- | --------- | ----------------- | ---------------------------------------------------------------- |
23+
| `ignoreBuildErrors` | `boolean` | `false` | Allow production builds to complete even with TypeScript errors. |
24+
| `tsconfigPath` | `string` | `'tsconfig.json'` | Path to a custom `tsconfig.json` file. |
25+
26+
## `ignoreBuildErrors`
27+
828
Next.js fails your **production build** (`next build`) when TypeScript errors are present in your project.
929

1030
If you'd like Next.js to dangerously produce production code even when your application has errors, you can disable the built-in type checking step.
1131

1232
If disabled, be sure you are running type checks as part of your build or deploy process, otherwise this can be very dangerous.
1333

14-
Open `next.config.js` and enable the `ignoreBuildErrors` option in the `typescript` config:
15-
1634
```js filename="next.config.js"
1735
module.exports = {
1836
typescript: {
@@ -24,3 +42,17 @@ module.exports = {
2442
},
2543
}
2644
```
45+
46+
## `tsconfigPath`
47+
48+
Use a different TypeScript configuration file for builds or tooling:
49+
50+
```js filename="next.config.js"
51+
module.exports = {
52+
typescript: {
53+
tsconfigPath: 'tsconfig.build.json',
54+
},
55+
}
56+
```
57+
58+
See the [TypeScript configuration](/docs/app/api-reference/config/typescript#custom-tsconfig-path) page for more details.

docs/01-app/03-api-reference/05-config/02-typescript.mdx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ Next.js generates global helpers for App Router route types. These are available
8080

8181
</AppOnly>
8282

83+
## `next-env.d.ts`
84+
85+
Next.js generates a `next-env.d.ts` file in your project root. This file references Next.js type definitions, allowing TypeScript to recognize non-code imports (images, stylesheets, etc.) and Next.js-specific types.
86+
87+
Running `next dev`, `next build`, or [`next typegen`](/docs/app/api-reference/cli/next#next-typegen-options) regenerates this file.
88+
89+
> **Good to know**:
90+
>
91+
> - We recommend adding `next-env.d.ts` to your `.gitignore` file.
92+
> - The file must be in your `tsconfig.json` `include` array (`create-next-app` does this automatically).
93+
8394
## Examples
8495

8596
### Type Checking Next.js Configuration Files
@@ -470,7 +481,7 @@ If you'd like Next.js to dangerously produce production code even when your appl
470481

471482
If disabled, be sure you are running type checks as part of your build or deploy process, otherwise this can be very dangerous.
472483

473-
Open `next.config.ts` and enable the `ignoreBuildErrors` option in the `typescript` config:
484+
Open `next.config.ts` and enable the `ignoreBuildErrors` option in the [`typescript`](/docs/app/api-reference/config/next-config-js/typescript) config:
474485

475486
```ts filename="next.config.ts"
476487
import type { NextConfig } from 'next'

0 commit comments

Comments
 (0)