如何使用 typescript 实现以下功能?
interface ActionType {
// how code?
type: string
};
let actionType: ActionType<{list: any}> = {
type: 'type',
list: []
}
听起来你在问一个通用的交叉点类型
// Generic type
// | Intersection type
// ↓ ↓
type ActionType<T> = T & { type: string };
const actionType: ActionType<{list: any[] }> = {
type: 'type',
list: []
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句