为什么tslint:recommended不允许使用模块? [英] Why is tslint:recommended not allowing modules?
问题描述
我们正在使用带有VS Code的打字稿v2.3.2和TSLint v4.5.1创建SPA.代码库正在增长,我们需要以某种方式对其进行模块化.
We are using typescript v2.3.2 and TSLint v4.5.1 with VS Code to create a SPA. Codebase is growing and we need to modularize it someway.
我尝试使用打字稿模块进行模块化,但是在编译应用程序时发现以下lint错误.
I tried to do the modularization using typescript modules but found the following lint error when transpiling the app.
[tslint] 'namespace' and 'module' are disallowed (no-namespace)
我正在为短绒棉使用此配置:
I'm using this configuration for the linter:
{
"extends": "tslint:recommended",
"rules": {
"no-var-requires": false,
"no-console": ["error", false],
"max-line-length": [false]
}
}
建议的规则文件显示在第89行这条规则:
The recommended rules file at line 89 shows this rule:
"no-namespace": true,
我想知道有什么问题吗,遵循不久之后就不会淘汰的良好实践,将SPA模块化的最佳方法是什么.
I wonder if there is something wrong and what would be the best way to modularize a SPA, following good practices that are not obsolete soon.
欢迎使用示例代码.非常感谢.
Examples of code will be welcomed. Thank you very much.
推荐答案
[tslint]不允许使用命名空间"和模块"(无命名空间)
[tslint] 'namespace' and 'module' are disallowed (no-namespace)
因为它们不是标准JavaScript语法.
- 命名空间是常见的JS模式的仅特殊TypeScript语法: https: //basarat.gitbook.io/typescript/docs/project/namespaces.html
- 请勿在
outFile
中使用命名空间: https://basarat. gitbook.io/typescript/docs/tips/outFile.html
- Namespace is a special TypeScript only syntax for a common JS pattern : https://basarat.gitbook.io/typescript/docs/project/namespaces.html
- Do not use namespaces with
outFile
: https://basarat.gitbook.io/typescript/docs/tips/outFile.html
这篇关于为什么tslint:recommended不允许使用模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!