You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Next.js provides an integrated [TypeScript](https://www.typescriptlang.org/) experience, including zero-configuration set up and built-in types for Pages, APIs, and more.
20
+
21
+
-[Clone and deploy the TypeScript starter](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-typescript&project-name=with-typescript&repository-name=with-typescript)
22
+
-[View an example application](https://github.com/vercel/next.js/tree/canary/examples/with-typescript)
23
+
24
+
## `create-next-app` support
25
+
26
+
You can create a TypeScript project with [`create-next-app`](https://nextjs.org/docs/api-reference/create-next-app) using the `--ts, --typescript` flag like so:
27
+
28
+
```
29
+
npx create-next-app@latest --ts
30
+
# or
31
+
yarn create next-app --typescript
32
+
```
33
+
34
+
## Existing projects
35
+
36
+
To get started in an existing project, create an empty `tsconfig.json` file in
You can also provide a relative path to a tsconfig.json file by setting `typescript.tsconfigPath` prop inside your `next.config.js` file.
46
+
47
+
Starting in `v12.0.0`, Next.js uses [SWC](https://nextjs.org/docs/advanced-features/compiler) by default to compile TypeScript and TSX for faster builds.
By default, Next.js will do type checking as part of `next build`. We recommend using code editor type checking during development.
72
+
73
+
> Instead of editing `next-env.d.ts`, you can include additional types by adding a new file e.g. `additional.d.ts` and then referencing it in the [`include`](https://www.typescriptlang.org/tsconfig#include) array in your `tsconfig.json`.
The`next.config.js`filemustbeaJavaScriptfileasitdoesnotgetparsedbyBabelorTypeScript, howeveryoucanaddsometypechecking in your IDE using JSDoc as below:
147
+
148
+
```js
149
+
// @ts-check
150
+
151
+
/**
152
+
* @type {import('next').NextConfig}
153
+
**/
154
+
const nextConfig = {
155
+
/* config options here */
156
+
}
157
+
158
+
module.exports = nextConfig
159
+
```
160
+
161
+
## Incrementaltypechecking
162
+
163
+
Since`v10.2.1`Next.jssupports [incrementaltypechecking](https://www.typescriptlang.org/tsconfig#incremental) when enabled in your `tsconfig.json`, this can help speed up type checking in larger applications.
164
+
165
+
Itishighlyrecommendedtobeonatleast`v4.3.2`ofTypeScripttoexperiencethe [bestperformance](https://devblogs.microsoft.com/typescript/announcing-typescript-4-3/#lazier-incremental) when leveraging this feature.
0 commit comments