取两个基类
interface Entity {}
interface Model {
toEntity(): Entity;
}
我需要创建一个方法,该方法接受Model的派生类,并将其转换为保留泛型类的实体
function convert<T extends Model, J extends T['toEntity']>(model: T) {
return model.toEntity();
}
然而,这就产生了
Type Entity is not assignable to type J. J could be instantiated with an arbitrary type which could be unrelated to Entity