I'm getting the above error on result[key] in
type DataType = Record<string, number>
export function getDifference<T extends DataType>(data1: T, data2: T): T {
const keys = Object.keys(data1)
return keys.reduce<T>((result, key) => {
result[key] = data1[key] - data2[key]
return result
}, {})
}
How do I get rid of it while still returning an generic type T so that the consuming functions still receive the correct type (instead of simply changing T to DataType).