![](/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.