create-next-app, TypeScript is configured automatically. To add TypeScript to an existing project, rename any file to .ts or .tsx and run next dev—Next.js will install the required dependencies and create a tsconfig.json with recommended settings.
tsconfig.json
The following is the recommendedtsconfig.json for a Next.js App Router project:
tsconfig.json
Do not modify
next-env.d.ts — it is regenerated automatically each time you run next dev, next build, or next typegen. Add it to .gitignore.TypeScript plugin
Next.js includes a custom TypeScript plugin and type checker that VSCode and other editors can use for advanced type-checking and auto-completion. Enable it in VS Code:
The plugin helps with:
- Warning when invalid values are passed to segment config options
- Showing available options and in-context documentation
- Ensuring the
'use client'directive is used correctly - Ensuring client hooks (like
useState) are only used in Client Components
Automatic type generation
Runningnext dev, next build, or next typegen generates a next-env.d.ts file that references Next.js type definitions and a hidden .next/types directory with route type definitions.
The next typegen command lets you generate types without running a full build:
Statically typed links
Next.js can statically typehref values in next/link and navigation methods in next/navigation, preventing broken links at compile time.
Enable typedRoutes in your config:
next.config.ts
.next/types/**/*.ts to your tsconfig.json include array (done automatically by create-next-app):
tsconfig.json
app/example-client.tsx
Type-safe environment variables
Next.js can generate TypeScript types for your environment variables, enabling IntelliSense forprocess.env in your editor.
next.config.ts
End-to-end type safety
The App Router supports end-to-end type safety for data fetching. Because Server Components run on the server, data returned fromfetch does not need to be serialized, and you can use Date, Map, Set, and other non-JSON types directly:
app/page.tsx
TypeScript configuration in next.config.js
Usenext.config.ts to get TypeScript type-checking in your config file:
next.config.ts
When
true, Next.js will not fail next build due to TypeScript errors. Run tsc --noEmit separately in CI to catch errors.Relative path to an alternate
tsconfig.json file used during next dev, next build, and next typegen.Custom type declarations
Do not modifynext-env.d.ts — it is overwritten on every build. Create a separate declaration file instead and reference it in tsconfig.json:
tsconfig.json
Node.js native TypeScript resolver
On Node.js v22.10.0+, Next.js detects the native TypeScript resolver viaprocess.features.typescript. When present, next.config.ts can use native ESM including top-level await.
For CommonJS projects targeting Node.js v22.10.0–v22.17.x, opt in with:
Version history
| Version | Changes |
|---|---|
v15.0.0 | next.config.ts support added |
v13.2.0 | Statically typed links available in beta |
v12.0.0 | SWC used by default to compile TypeScript for faster builds |
v10.2.1 | Incremental type checking support added |
