我收到此错误为什么扩展接口不能分配给匹配对象的泛型类型?
[ts] Type '{ type: string; }' is not assignable to type 'A'.
与下面的代码
interface Action {
type: string;
}
function requestEntities<A extends Action>(type: string) {
return function(): A {
return { type };
};
}
为什么不是分配? A
延伸Action
,它只有一个属性:type
,这是一个字符串。这里有什么问题?
问题A
可能有更多的属性?那么我如何告诉TypeScript,A
仍然只有type: string
属性而没有别的?
编辑
仅供参考,我想添加的通用A
是因为A
将有特定 string类型属性,例如原因{ string: 'FETCH_ITEMS' }
。