更新 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 找不到名称 'Opaque Token'。
我想我需要 d.ts 个匹配 alpha.46 的文件。经过几个小时的搜索和尝试,我无法做到这一点。我尝试使用 typings/angular2 上的命令行光标进行 npm install angular2,我得到了一个包含 12,031 行的错误日志,但没有新的 d.ts 文件。在很多事情中,我还尝试了Chrome的空缓存和硬重载。
如何获取 d.ts 匹配 angular2 版本的文件?是否可以自动更新以使其始终与 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
}
我看到了一个有趣的解决方案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>
我正在使用 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 找不到名称 'Opaque Token'。
我想我需要 d.ts 个匹配 alpha.46 的文件。经过几个小时的搜索和尝试,我无法做到这一点。我尝试使用 typings/angular2 上的命令行光标进行 npm install angular2,我得到了一个包含 12,031 行的错误日志,但没有新的 d.ts 文件。在很多事情中,我还尝试了Chrome的空缓存和硬重载。
如何获取 d.ts 匹配 angular2 版本的文件?是否可以自动更新以使其始终与 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
}
我看到了一个有趣的解决方案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>