我有以下类型声明
export declare type Education = {
id: string;
name: string;
} & ({
completed: false;
completionDate?: {year: number, month: number};
} | {
completed: true;
completionDate?: {
year: number;
};
})
现在我正在尝试转换以下对象
const a = {
id: 'id1',
name: 'testName'
completed: true
}
进入上述类型,但无法弄清楚completed为真而completed为false的情况。
例如,如果我有以下方法
const convert = (): Education =>{
return {
id: a.id,
name: a.name,
// Stuck here
}
}