[英]how to configure an angular project tsconfig paths[] without linting errors?
We have the following config in our tsconfig.ts我们的tsconfig.ts 中有以下配置
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@app/*": ["app/*"],
"@pages/*": ["app/pages/*"]
...
},
Then we can use much cleaner imports in our other ts files, something like this:然后我们可以在其他 ts 文件中使用更干净的导入,如下所示:
import {UrlConstants} from '@app/common/constants/url-constants';
Problem comes while linting the project: linting 项目时出现问题:
Module '@app/common' is not listed as dependency in package.json
Any way to solve it without going back to using ./***/***/
for imports?有什么方法可以解决它而无需返回使用
./***/***/
进行导入?
You can configure the rule with a whitelist as documented here https://palantir.github.io/tslint/rules/no-implicit-dependencies您可以使用此处记录的白名单配置规则https://palantir.github.io/tslint/rules/no-implicit-dependencies
That will look like this:看起来像这样:
tslint.json tslint.json
{
"rules": {
"no-implicit-dependencies": [
true,
[
"app",
"pages"
],
"dev"
]
}
}
The "dev" option isn't really for your scenario but it is useful if you lint your tests as I like to do. “dev”选项并不真正适合您的场景,但如果您按照我喜欢的方式整理测试,它会很有用。
Personally, I think the rule should be smarter and attempt to parse a tsconfig for paths to some extent.就个人而言,我认为规则应该更智能,并尝试在某种程度上解析路径的 tsconfig。 Sometimes one has many paths and not everyone uses NPM.
有时一个人有很多路径,并不是每个人都使用 NPM。 JSPM users might have to just disable the rule which is a shame because the rule is very well motivated and very useful if you don't hit this rough edge.
JSPM 用户可能不得不禁用该规则,这是一种耻辱,因为如果您没有达到这个粗略的边缘,该规则的动机非常好并且非常有用。
This should now work for @
prefixed paths as https://github.com/palantir/tslint/pull/4192 has been merged.这现在应该适用于
@
前缀路径,因为https://github.com/palantir/tslint/pull/4192已合并。 Until you can upgrade you may need to use "app"
and "pages"
.在升级之前,您可能需要使用
"app"
和"pages"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.