interface IYears {
one: string;
two: string;
three: string;
}
function transformYears(years: Array<keyof IYears>): [if all items of "years" includes in keyof IYears] ? IYears : Partial<IYears> {
return years.reduce((acc, year) => ({
...acc,
[year]: 'foo'
}), {})
}
const yearsFirst = transformYears(['one', 'two']) // type of yearsFirst is Partial<IYears>
const yearsSecond = transformYears(['one', 'two', 'three']) // type of yearsFirst is IYears
How modified transformYears
to match type of yearsFirst
and yearsSecond
? And possible check condition "if all items of "years" includes in keyof IYears" in ts?