---
title: "tsconfig.json"
description: "了解 Nuxt 如何管理项目中不同部分的 TypeScript 配置。"
canonical_url: "https://nuxt.zhcndoc.com/docs/3.x/directory-structure/tsconfig"
---
# tsconfig.json

> 了解 Nuxt 如何管理项目中不同部分的 TypeScript 配置。

Nuxt [会自动生成](https://nuxt.zhcndoc.com/docs/3.x/guide/concepts/typescript) `.nuxt/tsconfig.json` 文件，其中包含你在 Nuxt 项目中使用的解析后别名，以及其他合理的默认配置。

你的 Nuxt 项目应在根目录包含以下 `tsconfig.json` 文件：

```json [tsconfig.json]
{
  "extends": "./.nuxt/tsconfig.json"
}
```

::note
根据需要，你可以自定义此文件的内容。但建议不要覆盖 `target`、`module` 和 `moduleResolution`。
::

::note
如果你需要自定义 `paths`，这会覆盖自动生成的路径别名。相反，我们建议你将所需的路径别名添加到 `nuxt.config` 中的 [`alias`](https://nuxt.zhcndoc.com/docs/3.x/api/nuxt-config#alias) 属性，这样它们就会被获取并添加到自动生成的 `tsconfig` 中。
::

## 扩展 TypeScript 配置

你可以在 `nuxt.config.ts` 文件中，为 Nuxt 项目的各个环境（`app` 和 `server`）自定义 TypeScript 配置。
<!-- @case-police-ignore tsConfig -->

```ts twoslash [nuxt.config.ts]
// @errors: 2353
export default defineNuxtConfig({
  typescript: {
    // 自定义 tsconfig.app.json
    tsConfig: {
      // ...
    },
  },
  nitro: {
    typescript: {
      // 自定义 tsconfig.server.json
      tsConfig: {
        // ...
      },
    },
  },
})
```


## Sitemap

See the full [sitemap](https://nuxt.zhcndoc.com/sitemap.md) for all pages.
