`types` 选项无法按照 TS 文档中所述工作

问题描述 投票:0回答:1

我认为 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
 的自动导入建议不会出现。

typescript typescript-typings tsconfig tsconfig.json
1个回答
0
投票
从 VS Code 自动导入建议(需要包含的文件)中排除的唯一方法是使用:

{ // 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
 属性。

© www.soinside.com 2019 - 2024. All rights reserved.