@nuxt/typescript-build:Bridge 提供了相同的功能@nuxt/typescript-runtime 和 nuxt-ts:Nuxt 2 内置了运行时支持bridge.typescriptimport { defineNuxtConfig } from '@nuxt/bridge'
export default defineNuxtConfig({
bridge: {
typescript: true,
nitro: false, // If migration to Nitro is complete, set to true
},
})
tsconfig.json如果您正在使用 TypeScript,您可以编辑您的 tsconfig.json 以受益于自动生成的 Nuxt 类型
{
+ "extends": "./.nuxt/tsconfig.json",
"compilerOptions": {
...
}
}
.nuxt/tsconfig.json 是生成文件,不应提交到版本控制,因此您需要在运行测试之前生成该文件。在测试之前添加 nuxi prepare 步骤,否则您将看到 TS5083: 无法读取文件 '~/.nuxt/tsconfig.json'。对于现代 Nuxt 项目,我们建议使用TypeScript 项目引用,而不是直接扩展 .nuxt/tsconfig.json。./.nuxt/tsconfig.json 扩展的选项都将被您在 tsconfig.json 中定义的选项覆盖。使用您自己的配置覆盖诸如 "compilerOptions.paths" 之类的选项将导致 TypeScript 不考虑来自 ./.nuxt/tsconfig.json 的模块解析。这可能导致诸如 #imports 之类的模块解析无法识别。如果您需要进一步扩展 ./.nuxt/tsconfig.json 提供的选项,您可以在您的 nuxt.config 中使用 alias 属性。nuxi 将会识别它们并相应地扩展 ./.nuxt/tsconfig.json。