Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript mixins不';无法使用来自父级的泛型_Typescript - Fatal编程技术网

Typescript mixins不';无法使用来自父级的泛型

Typescript mixins不';无法使用来自父级的泛型,typescript,Typescript,我正在尝试用typescript实现mixin,并从mixin类中获得autocomplete。这是我的密码: export type Constructor<T> = new (...args: any[]) => T; export interface Test { methodA(); methodB(); } export type TestCtor = Constructor<Test>; export function mixinTes

我正在尝试用typescript实现mixin,并从mixin类中获得autocomplete。这是我的密码:

export type Constructor<T> = new (...args: any[]) => T;

export interface Test {
  methodA();
  methodB();
}


export type TestCtor = Constructor<Test>;


export function mixinTest<T extends Constructor<{}>>(base: T): TestCtor & T {
  return class extends base {

    constructor(...args: any[]) { super(...args); }

    methodA() { }

    methodB() {}

  };
}

class A<T> { 
  value: T;

  constructor(param: string) {}
}

class B extends mixinTest(A<{id: string}>) {
}

new B().methodA();
导出类型构造函数=new(…args:any[])=>T; 导出接口测试{ 方法a(); 方法b(); } 导出类型TestCtor=Constructor; 导出函数mixinTest(基:T):TestCtor&T{ 返回类扩展了基{ 构造函数(…args:any[]){super(…args);} methodA(){} methodB(){} }; } A类{ 值:T; 构造函数(参数:字符串){} } B类扩展混合测试(A){ } 新的B()方法a(); 但是我得到了一个错误:没有一个基构造函数有这个数字 指定的参数类型

或与通用:

应为1个参数,但得到3个

我缺少什么?

解决方案

....
class _Base extends A<{ id: string }> { }

class B extends mixinTest(_Base) {
}

new B('Hey!').methodA();
。。。。
类_Base扩展了{}
B类扩展了mixinTest(_Base){
}
新的B('Hey!')方法a();