Typescript-如何实现循环通用

问题描述 投票:1回答:1

我有以下代码:

interface BaseProps<TControl> {
  onEvent: (control: TControl) => void;
}

class BaseControl<TValue, BaseProps<any>> {
  onBlur = () => {
    onEvent(this); //subscriber must see the whole TS-class instead of BaseControl<TValue, BaseProps<any>>
  }
}

如您所见,我无法定义类的种类

class BaseControl<TValue, BaseProps<this>>> {}

或无限

class BaseControl<TValue, BaseProps<BaseControl<TValue, BaseProps<...etc.>>>> {}

有什么方法可以实现类似的通用指针? BaseProps<this>

typescript typescript-generics circular-reference self-reference
1个回答
0
投票

输入

© www.soinside.com 2019 - 2024. All rights reserved.