簡體   English   中英

更新angular2.d.ts和router.d.ts以匹配angular2版本

[英]Update angular2.d.ts and router.d.ts to match the angular2 version

我正在使用Atom-typescript在Atom中開發一個使用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文件。 經過幾個小時的搜索和嘗試,我無法實現這一目標。 我在鍵入/ angular2上嘗試使用命令行光標在npm install angular2上安裝,但出現錯誤日志,其中包含1,2031行,但沒有新的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
}

我在這里看到了一個有趣的解決方案,至少在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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM