Pan*_*ood 9 typescript typescript2.0
我怀疑 tsconfig.json继承是否能正常工作。并且“typeRoots”设置没有正确继承或根本没有继承。
http://www.typescriptlang.org/docs/handbook/tsconfig-json.html
(文件夹结构如下)
web.site -> tsconfig.json
- typings
- node_modules
- scripts
- ts
- tests
- ts -> tsconfig.json (this tsconfig extends/inherits web.site - see contents below)
Run Code Online (Sandbox Code Playgroud)
如果我在我的 web.site 文件夹中运行 tsc 命令,它会找到类型并成功编译。大概是因为它正确使用了typeRoots设置。
如果我在我的测试文件夹中运行 tsc 命令,它找不到任何类型并且无法编译。您可以假设错误只是无法找到它应该在“typings”文件夹中找到的声明的引用。
我可以将相同的文件从测试(失败)复制到根 web.site,然后它成功编译。
显然,它没有正确使用 tsconfig.json 因为给定继承,我已经设置,它应该通过继承的typeRoots设置找到类型。但不是。
我应该忽略继承作为半生不熟的东西并为此使用单独的 tsconfigs 吗?
在 web.site/tsconfig.json 中:
{
"compileOnSave": true,
"compilerOptions": {
"listFiles": true,
"removeComments": true,
"sourceMap": true,
"module": "es6",
"moduleResolution": "classic",
"outDir": "scripts/js",
"typeRoots": [
"node_modules/@types",
"typings"
]
},
"include":[
"scripts/ts/**/*"
]
Run Code Online (Sandbox Code Playgroud)
}
在测试/tsconfig.json 中:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "js",
"removeComments": false
},
"include": [
"ts/**/*"
]
}
Run Code Online (Sandbox Code Playgroud)
这个问题有两个部分:
了解哪些属性可以继承,哪些属性不能继承
尽管我没有找到任何官方文档,但在原始配置继承提案中,有一些关于哪些属性可以继承以及哪些属性必须位于叶配置文件中的讨论。
根据我的实验,我发现一些基于路径的属性(例如baseUrl和paths)无法继承。我没有尝试过使用typeRoots,所以我不能肯定地说,但设计可能不支持它。
了解如何解析相对路径
解析路径时,TypeScript 将使用叶配置文件的位置(称为“原始文件”)作为解析相对路径的当前工作目录。
在您提到的示例中,无法成功配置继承typeRoots,因为在同级文件夹中使用 are 时,而在上面的祖先文件夹中使用web.site/tsconfig.jsonare时。node_modulestests/tsconfig.jsonnode_modules
| 归档时间: |
|
| 查看次数: |
3023 次 |
| 最近记录: |