Faced very strange ts behaviour.
type Labels = Record<string, boolean | undefined>
type LabelGroups = Record<string, Labels>
export function reduceLabelGroups(labelGroups: LabelGroups) {
const labels = Object.entries(labelGroups).reduce((valueMap, [, value]) => ({...valueMap, ...value}), {});
return labels;
}
It should return Labels Type after reduce - but it returns just {} If you try to assert Labels like a
(...{} as Labels);
it throws error "Unnecessary cast: Array#reduce accepts a type parameter for the default value." How can I return type without any "as unknown as Labels" after return?