0
私はTypescriptを継承を提供するextend()
関数を持つ擬似クラスを持つJSライブラリで使用しようとしています。私は、新しい「クラス」に別のコンストラクタ関数を渡す方法についてこだわっている:Typescriptは汎用コンストラクタ関数を定義します
type A = (param1: string, param2: number);
type B = (param3: number, param4: number);
interface BaseClass {
extend<Constructor>(): {
new(); // How would I associate this function with type Constructor?
}
}
var NewClass = BaseClass.extend<A>();
new NewClass('Hello world', 3); // type checked against type A
var SecondClass= BaseClass.extend<B>();
new SecondClass(4, 5); // type checked against type B
私はこの試みた:
interface BaseClass {
extend<Constructor>(): {
new(): Constructor;
}
}
をしかし、それはnew NewClass()
への復帰型A.
私はこれを試してみた:
interface BaseClass {
extend<Constructor>(): {
new<Constructor>();
}
}
しかし、それはタイプチェックではありませんnew NewClass()
。
関数を型に関連付ける正しい構文は何ですか?