升级到 typescript 2.0.3 和 Angular 2.0.0 后,导入库本质上是使用 systemjs 在黑暗中拍摄。
即使使用 gulp-typescript 构建 TS 工作正常,Visual Studio 也拒绝相信这些模块存在。
示例 system.js
// map tells the System loader where to look for things
var map = {
...
'angular2-modal': '../lib/angular2-modal',
'angular2-modal/plugins/bootstrap': '../lib/angular2-modal/plugins/bootstrap'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
...
'angular2-modal': { defaultExtension: 'js', main: 'index' },
'angular2-modal/plugins/bootstrap': { defaultExtension: 'js', main: 'index' },
};
但是,如果我使用 gulp-typescript 构建,则不会出现任何错误,并且模块已成功加载到浏览器中。
我什至可以探索导入的模块。
我的 tsconfig 如下。
{ "compileOnSave": true,
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"noEmitOnError": true,
"inlineSources": true
//,"outDir": "client/build/",
//"outFile": "client/build/all.js",
//"declaration": true
},
"exclude": [
"node_modules",
"wwwroot/lib",
"typings/main",
"typings/main.d.ts"
],
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd"
}
}
自从升级到 typescript 2.0.3 以来,这一直是个问题。