问题
enum Type { Title = 'Title', Input = 'Input', } type InputCOnfType= number; type TitleCOnfType= string // map 1 对 1 type COnfList= { [Type.Input]: InputConfType, [Type.Title]: TitleConfType, }; // 想生成一个接口 A, 确保 type 和 conf 获得对应类型, 适用于以下情况 const Input : A ={ type: Type.Input, conf: 11 } const Title : A ={ type: Type.Title, conf: 'str' } // 如果出现有以下情况则报错 const ErrorTemplate : A ={ type: Type.Input, conf: 'str } 想象中的 A 接口 效果 类似于, 求解....
interface A < T=ConfList, K=keyof T > { type: K; conf: T[K] } 吐槽
Ts 想写完美, 特别是涉及 约束 真像是戴着镣铐跳舞....
as 一把梭又感觉不太优雅~~~
