我认为 TSConfig
types
选项不能像 TS 文档中所述那样工作。
我安装了 npm 软件包,express
、
@types/express
、
node
、
@types/node
、
lodash
、
@types/lodash
和
moment
。 我像下面这样编写了 TSConfig。
{
"include": ["./main.ts", "./src"],
"exclude": ["./src/**/DummyComp.ts"],
"compilerOptions": {
"outDir": "./dist",
"target": "ES5",
"types": ["node", "express"]
}
}
如 TS 文档中所述,应仅包含 type definition files
和
node
中的
express
,并且导出将显示为自动导入建议。但是
moment
和
lodash
的自动导入推荐(在
type
选项中省略)如下图所示。这怎么可能?
如 TS 文档中所述,
lodash
和
moment
的自动导入建议不会出现。
{
// Note that `javascript.preferences.autoImportFileExcludePatterns` can be specified for JavaScript too.
"typescript.preferences.autoImportFileExcludePatterns": [
"**/node_modules/@types/node"
]
}
TypeScript 4.8 引入了编辑器首选项,用于从自动导入中排除文件。在 Visual Studio Code 中,可以在设置 UI 的“自动导入文件排除模式”下或 .vscode/settings.json 文件中添加文件名或 glob:https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#exclude-specific-files-from-auto-imports
exclude
中的
tsconfig.json
属性。