Currently facing an issue with Typescript that I'm stuck on.
I have created a named callback Handler class that receives the allowed list of "events"/"handlernames" as a generic:
class NamedHandler<H extends { [key: string]: HandlerFunction }> {
...
Using this in other classes works well for simple use cases within one class.
export class MyClass<H extends { [key: string]: HandlerFunction }> {
protected commandHandler = new NamedHandler<H>();
...
}
type SimpleHandlers = {
handlerA: (param: number) => Promise<void>;
}
class SimpleClass<H extends { [key: string]: HandlerFunction }> extends MyClass<SimpleHandlers> {
However, extending from this class and expanding the permissible "handler names" seems to be a challenge without a clear solution at the moment.
An example has been provided in the TS Playground
If anyone has any insights on solving this or alternative approaches, it would be greatly appreciated. Thank you.