【问题标题】:Update angular2.d.ts and router.d.ts to match the angular2 version更新 angular2.d.ts 和 router.d.ts 以匹配 angular2 版本
【发布时间】:2015-11-30 22:24:21
【问题描述】:

我正在 Atom 中使用 atom-typescript 开发一个使用 Angular2 的小型测试应用程序。我对 angular2.d.ts 的初始设置使用了 alpha.28,而 router.d.ts 使用了 alpha.31。我已将 index.html 更新为 alpha.46

<script src="https://code.angularjs.org/2.0.0-alpha.46/angular2.dev.js"></script>
<script src="https://code.angularjs.org/2.0.0-alpha.46/router.dev.js"></script>

现在,当我导入 ROUTE_PROVIDERS 之类的内容时,atom-typescript 会给我一个未找到的错误。我也得到 router.d.ts 找不到名称“不透明令牌”。

我想我需要匹配 alpha.46 的 d.ts 文件。经过几个小时的搜索和尝试,我无法做到这一点。我尝试 npm install angular2 将命令行光标放在 typings/angular2 上,我得到一个错误日志,其中包含 12,031 行,但没有新的 d.ts 文件。在很多方面,我还尝试了 Chrome 的空缓存和硬重载。

如何获得与 angular2 版本匹配的 d.ts 文件?是否可以自动更新,使其始终与 index.html 中的 angular2 版本匹配?

如果有帮助,这是我的 tsconfig.json 文件

{
  "compilerOptions": {
    "charset": " UTF-8",
    "declaration": false,
    "diagnostics": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "listFiles": true,
    "module": "commonjs",
    "noImplicitAny": false,
    "noLib": false,
    "outDir": "dist/js/cjs",
    "rootDir": "src",
    "removeComments": true,
    "sourceMap": true,
    "target": "es5",
    "version": true
  },
  "filesGlob": [
    "./**/*.ts",
    "!node_modules/**"
  ],
  "exclude": [
    "node_modules"
  ],
  "files": [
    "./app.ts",
    "./src/components/navigation/home.ts",
    "./src/components/navigation/postApartment4Rent.ts",
    "./typings/angular2/angular2.d.ts",
    "./typings/angular2/router.d.ts",
    "./typings/es6-promise/es6-promise.d.ts",
    "./typings/rx/rx-lite.d.ts",
    "./typings/rx/rx.d.ts",
    "./typings/tsd.d.ts"
  ],
  "atom": {
    "rewriteTsconfig": true
  },
  "buildOnSave": true,
  "compileOnSave ": true
}

【问题讨论】:

  • 查看issue
  • 埃里克,谢谢。我在您发送给我的问题页面上发布了我收到的错误的描述。我可能搞砸了,但我认为 angular2 团队需要做一些工作才能让 typescript 在 IDE 中为最近的 alpha 版本工作。
  • 我发布的问题是我的。我修复了它们,npm 将 alpha.47 安装到我的项目代码中。 atom-typescript 仍然没有找到像 ROUTE_PROVIDERS 这样的新实体。我可能要等到更多 angular2 文档出来。

标签: typescript angular atom-editor


【解决方案1】:

我看到了一个有趣的解决方案here,至少在 ng2 版本不断变化时,我已将其用于开发代码:

1) 在 gulp 文件中:

gulp.src('node_modules/angular2/bundles/angular2.dev.js').pipe(gulp.dest(dest_lib));
gulp.src('node_modules/angular2/bundles/router.dev.js').pipe(gulp.dest(dest_lib));
gulp.src('node_modules/systemjs/dist/system.src.js').pipe(gulp.dest(dest_lib));

2) 在您的 index.html 文件中

<script src="lib/system.src.js"></script>
<script src="lib/angular2.dev.js"></script>
<script src="lib/router.dev.js"></script>

【讨论】:

  • 我不使用 Gulp,所以我不能测试/保证这个解决方案,但我认为你“把你的东西放在一起”。谢谢。我的最新问题是我已经为 angular2.d.ts 更新了我的 tsd.json 文件,但是我无法在 tsd.json 中为路由器获取已安装的提交。因此 atom-typescript 为路由器使用旧的 d.ts 文件。我使用 Bash 尝试 tsd install angular-new-router -ros 并得到响应 - 没有结果。我也尝试过删除旧的 router.d.ts 文件并进行新的 tsd 安装,但我再次得到 - 没有结果 - 并且在 tsd.json 中没有安装提交。
猜你喜欢
  • 1970-01-01
  • 2017-06-27
  • 2015-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多