Why is tslint:recommended not allowing modules?

≯℡__Kan透↙ 提交于 2019-12-18 12:47:19

问题


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.

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]
  }
}

The recommended rules file at line 89 shows this rule:

"no-namespace": true,

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.


回答1:


[tslint] 'namespace' and 'module' are disallowed (no-namespace)

Because the are not standard JavaScript syntax.

More

  • Namespace is a special TypeScript only syntax for a common JS pattern : https://basarat.gitbooks.io/typescript/docs/project/namespaces.html
  • Do not use namespaces with outFile : https://basarat.gitbooks.io/typescript/docs/tips/outFile.html


来源:https://stackoverflow.com/questions/44202309/why-is-tslintrecommended-not-allowing-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!