I'm looking for the Typescript compiler (TSC) to throw errors when I make mistakes in signatures.
export class EventEmitter<EventTypes extends { [key: string]: any }> {
subscribe<Event extends keyof EventTypes>(type: keyof EventTypes, fn: <T extends EventTypes[Event]>(value: T) => any) {
}
}
export class Data {
name: string;
}
export class Experiment extends EventEmitter<{ "next": Data, "end": Data[] }> {
}
new Experiment().subscribe("end", (v: Date) => {});
My understanding is that tsc should flag the error in (v: Date) since Date is not of type Data[]. How can this be achieved?