gpt4 book ai didi

即使在排除它们之后, typescript 也会在 node_modules 下编译类型

转载 作者:行者123 更新时间:2023-12-01 11:18:25 25 4
gpt4 key购买 nike

在尝试编译我的 typescript 源代码时,我看到编译器也在尝试编译我的 node_modules 文件夹下的类型。
我正在使用 typescript 2.6.1,我的 tsconfig 文件如下

 {
"compilerOptions": {
"allowSyntheticDefaultImports":true,
"outDir": "./dist",
"mapRoot": "./dist",
"module": "commonjs",
"target": "es6",
"sourceMap": true,
"sourceRoot": "./source",
"removeComments": false
},
"exclude": [
"node_modules",
"test"
],
"include": [
"source/*.ts"
]
}

当我运行以下命令“tsc -w -p tsconfig.json”时,出现以下错误
 node_modules/@types/es6-promise/index.d.ts(11,15): error TS2300: Duplicate identifier 'Promise'.

最佳答案

看完这篇文档,我得到了答案
https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

在@types、typeRoots 和类型部分下

他们提到

指定 "types": [] 以禁用自动包含 @types 包。

更新后的 tsconfig.json 如下

{
"compilerOptions": {
"allowSyntheticDefaultImports":true,
"outDir": "./dist",
"mapRoot": "./dist",
"module": "commonjs",
"target": "es6",
"sourceMap": true,
"sourceRoot": "./source",
"removeComments": false,
"types": []
},
"exclude": [
"node_modules",
"test"
],
"include": [
"source/*.ts"
]
}

关于即使在排除它们之后, typescript 也会在 node_modules 下编译类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47303252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com