我发现了一个场景,我可以可靠地让 TypeScript 编译器失败并显示错误消息:“内部错误:无法获取属性‘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 编译器崩溃的副本: publicMembers 为 null 或 undefined,但重现明显不那么复杂,所以我想我还是会继续发布它。
有什么想法吗?