我發現一種情況,我可以可靠地獲得打字稿編譯器失敗,出現錯誤信息:「內部錯誤:無法獲取財產「publicMembers」的值:對象爲null或undefined」打字稿編譯器錯誤:「無法獲得屬性‘publicMembers’的值:對象爲空或未定義」
這是我的Repro.ts文件:
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.");
}
}
這很可能是TypeScript compiler crash: publicMembers is null or undefined重複,但攝製是顯著不那麼複雜,所以我想我會繼續併發布它。
有什麼想法?
有幫助,謝謝。比我的建議更好。 –