并非所有打字稿文件都使用 atom-typescript 编译为 js

Not all typescript files compile to js using atom-typescript

我正在学习在 Angular2 中构建路由的教程 https://www.youtube.com/watch?t=10&v=ZsGRiHSaOxM 它显示了使用 .ts 构建的部分页面,并且在每种情况下都有一个配套的 .js 文件。我的带有 atom-typescript 的 Atom 编辑器在我更改文件时将 app.ts 文件编译为 app.js,但据我所知,我在另一个目录中的部分页面无法编译。

当文件为 homePage.ts 时,控制台错误为 - 找不到 homePage.js 当文件为 homePage.js 时,控制台错误为 - unexpected token @ on line (where @组件是)。我的 tsconfig 中有 "compileOnSave ": true,该文件位于顶级项目目录中。

我尝试将 fileGlob 放在 tsconfig 中,来自文档,如下

"filesGlob": [
    "./**/*.ts",
    "!./node_modules/**/*.ts"
],

没有任何变化。

我的编译器选项是:

"compilerOptions": {
    "charset": " UTF-8",
    "declaration": false,
    "diagnostics": true,
    "emitDecoratorMetadata": true,
    "module": "commonjs",
    "noImplicitAny": false,
    "noLib": false,
    "removeComments": true,
    "sourceMap": true,
    "target": "es5",
    "version": true
},

所有组件都需要 .ts 和 .js 文件吗?如果需要,我该如何使用 atom-typescript 实现?或者为什么我会收到意外的令牌@错误?

Or why do I get the unexpected token @ error

您需要将 experimentalDecorators 设置为 true。所以:

"compilerOptions": {
    "charset": " UTF-8",
    "declaration": false,
    "diagnostics": true,
    "experimentalDecorators", true,
    "emitDecoratorMetadata": true,
    "module": "commonjs",
    "noImplicitAny": false,
    "noLib": false,
    "removeComments": true,
    "sourceMap": true,
    "target": "es5",
    "version": true
},

FWIW 这就是装饰器在 TypeScript 编译器中的实现方式