function Mix<T extends new (...args: any[]) => any>(Base: T) {
abstract class Ext extends Base {
abstract map: { [key: string]: (...args: any[]) => any }
run<Key extends keyof this['map']>(
key: Key, args: this['map'][Key]
) { }
}
return Ext
}
class Foo extends Mix(Object) {
map = { 'test': (n: number) => 'ok'}
ctx() {
this.run('test', 3) // 3 is a number, so it should fit (n: number)
/*
Argument of type 'number' is not assignable to parameter of type 'this["map"]["test"]'.
Type 'number' is not assignable to type '(n: number) => string'.ts(2345) */
}
}
I want the second argument of this.run() to have to be whatever the parameter is of the function this.map['test']