2014-11-17 4 views
1

commonJS 모듈을 사용하여 라이브러리를 만들고 있는데 "lib"디렉토리의 자체 모듈에 클래스를 정의한 다음 클래스를 가져오고 내보내는 "main"모듈을 갖고 싶습니다. "lib"디렉토리에있는 모듈. 라이브러리의 소비자가 내 보낸 클래스를 확장 할 수 있기를 원하지만 타이프 스크립트 컴파일러는이를 지원하지 않는 것 같습니다. 아래의 코드는 내부 모듈을 사용하여 단순화 된 repro입니다. 컴파일러에서 클래스 BC에 대한 오류를 내 보냅니다. 해결 방법이 있습니까?typeof 변수에서 확장 할 수 없습니다

module A { 
    export class C { 
    } 
} 

module B { 
    export var C = A.C; 
} 

// this compiles 
class AC extends A.C { } 

// and this compiles 
var bc = new B.C(); 

// this does not compile. 
// compiler error: TS2305 Module 'B' has no exported member 'C' 
class BC extends B.C { 
} 

답변

4

당신은 유형 선언 공간 (import 키워드)가 아닌 변수 선언 공간 (var 키워드)에 A.C을 가지고해야합니다.

module A { 
    export class C { 
    } 
} 

module B { 
    export import C = A.C; 
} 

// this compiles 
class AC extends A.C { } 

// and this compiles 
var bc = new B.C(); 

// NO ERROR 
class BC extends B.C { 
} 
관련 문제