打字稿类型特定属性必需

时间:2019-04-11 08:33:27

标签: typescript types required-field

目标:

type Question = {
    id: string;
    answer?: string;
    thirdProp?: number;
    fourthProp?: number;
}

// usage Required<Question, 'answer' | 'thirdProp'> expect to equal
/*

type Question = {
    id: string;
    answer: string;
    thirdProp: number;
    fourthProp?: number;
}

*/

上面的例子应该很好解释。我想输入Required类型,它产生上面解释的结果。一个人怎么能做到呢?

0 个答案:

没有答案