[英]How typescript creates generic interfaces
How to use typescript to realize the following functions?如何使用typescript实现以下功能?
interface ActionType {
// how code?
type: string
};
let actionType: ActionType<{list: any}> = {
type: 'type',
list: []
}
Sounds like you're asking about a generic intersection type听起来您在询问通用交叉路口类型
// Generic type
// | Intersection type
// ↓ ↓
type ActionType<T> = T & { type: string };
const actionType: ActionType<{list: any[] }> = {
type: 'type',
list: []
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.