У меня есть иерархия классов классов, которые работают в простом JavaScript.
const
AsFoo = ( superclass ) => class extends superclass {
get foo(){ return true; }
},
AsFooBar = ( superclass ) => class extends AsFoo( superclass ){
get bar(){ return true; }
},
FooBar = AsFooBar( Object ),
fb = new FooBar();
console.log( fb.foo, fb.bar );
// true, true
Однако, когда я перевожу их на TypeScript, я получаю сообщение об ошибке с AsFoo( superclass )
.
type Constructor<T = {}> = new ( ...args: any[] ) => T;
interface Foo {
foo: boolean;
}
interface FooBar extends Foo {
bar: boolean;
}
const
AsFoo = <T extends Constructor>( superclass: T ): Constructor<Foo> & T => class extends superclass implements Foo {
get foo(){ return true; }
},
AsFooBar = <T extends Constructor>( superclass: T ): Constructor<FooBar> & T => class extends AsFoo<T>( superclass ) implements FooBar {
get bar(){ return true; }
};
// Type 'Constructor<Foo> & T' is not a constructor function type. ts(2507)
Что я могу сделать, чтобы TypeScript работал с этим шаблоном? Я бы предпочел не просто // @ts-ignore: ¯\_(ツ)_/¯
это.
В настоящее время я использую TypeScript 3.2.4.