2017-08-11 39 views
1

我有一個npm模塊,我用於一些我的Typescript項目common-types(回購:https://github.com/lifegadget/common-types)。最近添加的一個枚舉我有叫FirebaseEvent火力地堡的工作項目,其定義爲:奇怪的TS導入問題

export enum FirebaseEvent { 
    value = 'value', 
    child_added = 'child_added', 
    child_moved = 'child_moved', 
    child_removed = 'child_removed', 
    child_changed = 'child_changed' 
}; 

我遇到的問題是,當我嘗試導入枚舉以下表達式:

import { FirebaseEvent } from 'common-types'; 

我得到以下錯誤:

enter image description here

以供參考,常見類型文件的第5行是:

export interface IDictionary<T = any> { 
    [key: string]: T; 
} 

而且我強烈懷疑該錯誤消息是紅鯡魚,就好像我輸入以下任何它而不會出現錯誤:

import { IDictionary } from 'common-types'; 
import { IDictionary, datetime } from 'common-types'; 

然而,包括FirebaseEvent任何進口 - 如下面 - 失敗,與上述相同的錯誤消息:

import { IDictionary, FirebaseEvent } from 'common-types'; 

回答

1

我不會要求知道爲什麼這個作品,我也不會聲稱,我想出了這個想法,但很顯然,增加的出口空的類到您的common-types.ts文件將使您能夠導出您的枚舉而不會出現任何錯誤。

您面對的枚舉的確切問題是discussed here。查看用戶mtz2537和bits__and_bytes的評論。

另請訪問plunk they created以說明添加空類可解決問題。他們補充類很簡單:

export class env { 

} 

打開開發工具控制檯,嘗試刪除/添加的是從environment.ts文件中導出這個空類,你會看到他們的作品黑客。奇怪的是,你甚至不需要在任何地方導入這個類。只要包含你的枚舉的.ts文件也導出一個空的類,你就不會看到任何錯誤。

+0

我現在在我的空類上得到了語法錯誤:'export class __workaround__ {}' – ken