【发布时间】:2022-07-21 21:04:37
【问题描述】:
我在父文件夹store/aisle/fruits 中有一个tsconfig.json:
{
"compileOnSave": true,
"compilerOptions": {
.
.
"target": "es6",
"noEmitOnError" : true,
"noEmitHelpers": false,
"stripInternal": true,
"removeComments": true,
"declaration": true
}
}
我在store/aisle/fruits/mango 中有另一个tsconfig.json 来覆盖目标属性。 Price.ts 有一个 async/await 实现,我希望它在生成的 .js 文件中保持原样;因此,将target 值更改为ES2017:
{
"extends": '../tsconfig',
"compilerOptions": {
"target": "ES2017"
},
"files": ["Price.ts", "index.ts"]
}
但是,由于某种原因,tsc 似乎没有捕捉到mango 文件夹中tsconfig 中的更改,并覆盖了fruits 文件夹中的tsconfig。因此,生成的 .js 包括发出的帮助器 (__awaiter),这是我不想要的。
所以,我的问题是如何在我的price.js 文件中覆盖目标值以获得所需的效果(只有async/await 而不是__awaiter)?
【问题讨论】:
-
我的理解是 tsconfig 文件的行为不像 eslint 配置。当您运行
tsc时,您必须为整个构建选择一个,并且只选择一个配置文件。extends属性允许您选择的 tsconfig 文件从一个或多个其他 JSON 文件继承属性,但如果您在构建期间选择使用fruits/tsconfig,您的mango/tsconfig文件将被忽略。
标签: typescript tsconfig