2017-10-04 6 views
0

グローバル型と同じ名前の型があります。具体的には、イベント。TypeScript同じ型の名前空間内でグローバル型を使用する

私はイベントをネームスペース内に置いています。ネームスペース内でイベントを参照するのは簡単ですが、ネームスペース内ではグローバル(または標準)イベントを参照することはできません。

namespace Dot { 
    export class Event { 
     // a thing happens between two parties; nothing to do with JS Event 
    } 
    function doStuff(e : Event) { 
     // Event is presumed to be a Dot.Event instead of usual JS event 
     // Unable to refer to global type? 
    } 
} 
function doStuff2(e : Event) { 
    // Use of regular Event type, cool 
} 
function doStuff3(e : Dot.Event) { 
    // Use of Dot event type, cool 
} 

これは単純には不可能だと思われますが、これは確認できますか? Dot.Event型の名前を変更する以外の回避策はありますか?

乾杯

+1

関連:https://github.com/Microsoft/TypeScript/issues/983 – xmojmr

答えて

3

あなたグローバルEventタイプを表すタイプを作成し、名前空間の中にそれを使用することができます:

type GlobalEvent = Event; 

namespace Dot { 
    export class Event { 
     // a thing happens between two parties; nothing to do with JS Event 
    } 
    function doStuff(e : GlobalEvent) { 
     // Event is presumed to be a Dot.Event instead of usual JS event 
     // Unable to refer to global type? 
    } 
} 
function doStuff2(e : Event) { 
    // Use of regular Event type, cool 
} 
function doStuff3(e : Dot.Event) { 
    // Use of Dot event type, cool 
} 

しかし、私の推薦は、のために、他のあなたの専門分野の何かを呼び出すことであろう例DotEvent

+0

これは私が探していたものです。 Dotのコードの大部分はDotEventを使用しています.Dotイベントリスナーは標準イベントが必要です.GlobalEventメソッドを使用します。乾杯 – Phi

関連する問題