![](/img/trans.png)
[英]Why does TypeScript throw the error: TS2339: Property 'error' does not exist on type 'EventTarget'
[英]Typescript declaration: why does this throw an error
我只是在学习打字稿。 我正在编写一个带有SystemJS 0.15.31
typescript 2
的Angular 2
应用程序,使用SystemJS 0.15.31
作为我的模块加载器。
我想定义应用程序范围的常量。 在一个文件中,并根据需要将其导入到我的组件中。 这就是我所拥有的:
根/systemjs.config.js
System.config({
map:{
'app': 'dist',
'config': 'dist/config',
...
}
});
root/dev/config.ts
export module Config {
var version:string = '1';
}
root/dev/app/app.component.ts
import {Config} from 'config';
...
export class AppComponent {
...
version = Config.version;
}
转换为 Javascript 后, .ts
文件放在dist/
。 然而,打字稿编译器显示此错误上的第一行app.component.ts
并在浏览器, AppComponent
没有看到Config.version
错误 TS2307:找不到模块“配置”。
我的语法有什么问题?
我认为您的问题是 SystemJS 期望dist/config
是一个文件夹。
向文件路径添加扩展名,如下所示:
map: {
...
'config': 'dist/config.js'
...
}
PS: export module
不是打字稿。 我想你想要:
export const Config = {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.