2017-10-04 1 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

관련 문제