interface ComplexObject {
mandatory: string;
title1?: string;
title2?: string;
}
type GetOptional<T> = {
};
type Option = GetOptional<ComplexObject>;
function createApp(option: Option) {
// {title1?: string; title2?: string;}
}
上述的代码我们期望通过GetOptional
处理后的Option
属性为{title1?: string; title2?: string;}
提出接口的所有字段
interface ComplexObject {
mandatory: string;
title1?: string;
title2?: string;
}
type GetOptional<T> = {
[P in keyof T]<