I have a scenario here where I am extending a node called EventEmitter
with my class. The goal is to restrict the events that can be registered.
class Foo extends EventEmitter {
on(event: 'myEvent', listener: Function): this;
emit(event: 'myEvent', ...args: any[]): boolean
}
var foo = new Foo();
foo.on('wrongEvent', ()=>{}); // Ideally, this should trigger a compilation error
Do you think this can be done?
Currently facing an issue:
t.ts(6,3): error TS2391: Function implementation is missing or not immediately following the declaration.
t.ts(7,3): error TS2391: Function implementation is missing or not immediately following the declaration.
t.ts(10,8): error TS2345: Argument of type '"wrongEvent"' is not assignable to parameter of type '"myEvent"'.
Any suggestions on how to handle the TS2391 error effectively?