#Function type arguments ignored for `Array.prototype.reduce` when array is generic

1 messages · Page 1 of 1 (latest)

fading matrixBOT
#
makk0#0

Preview:```ts
function foo<K extends PropertyKey>(
keys: K[]
): Record<K, any> {
return keys.reduce<Record<K, any>>(acc => acc, {})
}

function bar<K extends PropertyKey>(
keys: K[]
): Record<K, any> {
return keys.reduce(acc => acc, {} as Record<K, any>)
}```

fleet lance
#

As far as I know, these two approaches (specifying the generic type via angle brackets and specifying it via a type assertion) are equivalent for Array.prototype.reduce, but here the first one errors and the second doesn't