Angular 2 在 Sublime Text 3 中有错误

标签 angular sublimetext3

我尝试基于以下存储库在 Windows 上的 Angular 2 中启动一个新项目:https://github.com/mgechev/angular2-seed

一切正常(npm installnpm start,...)除了 Sublime Text 3 向我显示了一些在我执行项目时不存在的错误。

以下是我遵循的步骤:

$ git clone https://github.com/mgechev/angular2-seed.git
$ cd angular2-seed
$ npm install

然后我用 Sublime Text(带有 TypeScript package )打开项目,我在代码中遇到了一些错误/警告。

错误 #1

带有 @Component 装饰器的类显示以下错误:

Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.

(它忽略 tsconfig.json 中的 "experimentalDecorators": true 行)

错误 #2

例如在src/client/app/about/about.component.ts中,一行:

  moduleId: module.id,

Sublime 显示此错误:

Cannot find name 'module'.

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": false,
    "removeComments": true,
    "noLib": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "es2015", "dom"],
    "sourceMap": true,
    "pretty": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitUseStrict": false,
    "noFallthroughCasesInSwitch": true,
    "typeRoots": [
      "./node_modules/@types",
      "./node_modules"
    ],
    "types": [
      "node"
    ]
  },
  "exclude": [
    "node_modules",
    "dist",
    "src"
  ],
  "compileOnSave": false
}

package.json

https://github.com/mgechev/angular2-seed/blob/27db8a19f70470f5110482df1a4debc1100ec347/package.json

你知道为什么我有这 2 个错误吗?我可以发展,但不是很愉快。

最佳答案

感谢此链接,我解决了我的问题:https://github.com/Microsoft/TypeScript-Sublime-Plugin/issues/470

总结:

  • 转到用户首选项(Ctrl + Shift + P > 首选项:设置)
  • 添加以下行:"typescript_tsdk": "C:/....../npm/node_modules/typescript/lib",(带有适当的链接)
  • 重启 Sublime Text
  • 当光标位于 module.id 上时按 F12 测试它是否在 about.component.ts 文件中工作
  • 尽情享受吧!

关于Angular 2 在 Sublime Text 3 中有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39756578/

相关文章:

angular - 如何以编程方式隐藏 ngx-toaster?

angular - 等待父组件/模块加载数据

python - input() 命令不适用于 Sublime Text 3

html - Angular 5 : Spinner is not working perfectly on page load

angular - mat-autocomplete 在输入焦点上自动隐藏占位符文本

Angular dom不更新更改

python - MacOSX 上带有 python 的 Sublime Text 3 -- 模块缺少其方法

html - 如何在 Sublime Text 3 中格式化 HTML

javascript - 如何使用 sublime text 和 Live Reload 调试 AngularJS 应用程序

javascript - 在 Sublime text 中使用来自控制台的输入运行节点 js