2012-11-12 4 views
0

오류 메시지와 함께 실패 할 수있는 TypeScript 컴파일러를 안정적으로 얻을 수있는 시나리오를 발견했습니다. "내부 오류 : 재산 'publicMembers'의 값을 가져올 수 없습니다 :이 아주 잘 TypeScript compiler crash: publicMembers is null or undefined의 중복 될 수있다Typescript 컴파일러 오류 : "publicMembers '속성 값을 가져올 수 없습니다. 개체가 null이거나 정의되지 않음"

interface Callback { (data: any): void; } 

class EventSource1 { 
    addEventHandler(callback: Callback): void { } 
} 

class EventSource2 { 
    onSomeEvent: Callback; 
} 

export class Controller { 
    constructor() { 
     var eventSource = new EventSource1(); 
     // Commenting the next line will allow it to compile. 
     eventSource.addEventHandler(msg => this.handleEventFromSource1(msg)); 
    } 
    private handleEventFromSource1(signalState) { 
     console.log('Handle event from source 1'); 
     var eventSource2 = new EventSource2(); 
     // Commenting the next line will allow it to compile. 
     eventSource2.onSomeEvent = msg => this.handleEventFromSource2(msg); 
    } 
    private handleEventFromSource2(event) { 
     console.log("Handling event from source 2."); 
    } 
} 

하지만 생식이 상당히입니다 : 개체가 null 또는

다음

내 Repro.ts 파일의 "정의되지 덜 복잡한, 그래서 나는 어쨌든 가서 그것을 게시 할 줄 알았다.

의견이 있으십니까?

답변

3

나는 이것을 bug over on Codeplex에 추가했습니다.

버그가 아직 문제가 있음을 나타내지 않은 경우 해당 버그에 투표해야합니다.

당신이 옳은 답변을 추가 할 수있는 게 많지 않습니다. 이것은 컴파일러의 버그입니다. 우리는 단지 수정을 기다릴 필요가 있습니다.

1

무슨 가치가 있는지, 내가 지금까지 문제 (컴파일러 버그를 고칠 때까지)에서 찾은 최고의 해결 방법은 명명 된 콜백 인터페이스를 피하는 것입니다. 즉,이 코드는 잘 작동합니다.

class EventSource1 { 
    addEventHandler(callback: { (data: any): void; }): void { } 
} 

class EventSource2 { 
    onSomeEvent: { (data: any): void; }; 
} 

class Controller { 
    constructor() { 
     var eventSource = new EventSource1(); 
     eventSource.addEventHandler(msg => this.handleEventFromSource1(msg)); 
    } 
    private handleEventFromSource1(signalState) { 
     console.log('Handle event from source 1'); 
     var eventSource2 = new EventSource2(); 
     eventSource2.onSomeEvent = msg => this.handleEventFromSource2(msg); 
    } 
    private handleEventFromSource2(event) { 
     console.log("Handling event from source 2."); 
    } 
} 
2

다른 해결 방법은 다음과 같습니다. 메서드에 대해 void 반환 유형을 선언하십시오.

+0

도움, 감사합니다. 그리고 내 제안보다. –