TypeScript 2.1+ tsconfig 扩展

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

目前,我正在尝试 tsconfig.json 中的新扩展功能,它允许开发人员拥有一个基础 tsconfig.json,其他模块可以扩展/修改。

它正在工作,尽管不如预期。不知何故,让这个工作的唯一方法是在父配置和子配置中指定 compileoptions.lib。

parent.tsconfig.json

 {
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "lib": [ // Lib compiler options defined!!! 
      "dom",
      "es6"
    ]
  },
  "exclude": [
    "node_modules"
  ],
  "awesomeTypescriptLoaderOptions": {
    "resolveGlobs": true,
    "forkChecker": true
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

child.tsconfig.json(预期)

{
  "extends": "../parent.tsconfig.json",
}  

child.tsconfig.json(工作需要)

{
  "extends": "../parent.tsconfig.json",
  "compilerOptions": {
    "lib": [ //Have to specify lib again ==> Double-u-t-f
      "dom",
      "es6"
    ]
  }
}

关于此事的一些建议将不胜感激。

干杯

typescript tsconfig
2个回答
0
投票

你做的一切都是对的。您的

tsconfig.json
文件应该位于当前项目的根目录中。仔细检查
parent.tsconfig.json
文件的路径是否在您的
child.tsconfig.json
中正确设置。


0
投票

就我而言,我在父文件夹中运行

tsc
命令,它只使用父文件夹中的
tsconfig.json
而不是子文件夹中的命令。

在子文件夹中运行

tsc
命令时有效,或者从父文件夹运行
tsc -p child_folder_name
也有效。

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