首页 > 解决方案 > 打字稿类型 特定属性所需

问题描述

目标:

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产生上述结果的类型。怎么能做到这一点?

标签: typescripttypesrequired-field

解决方案


推荐阅读