You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the reduce function is called from const result = (item: T) => keys.reduce TS appears to be inferring the signature of reduce to be reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;. When the function is inlined, the signature of reduce is inferred to be reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;.
Question:
Is this signature needed?
reduce(callbackfn: (previousValue: T,currentValue: T,currentIndex: number,array: readonlyT[])=>T,initialValue: T): T
This signature would seem to satisfy those constraints.
reduce<U>(callbackfn: (previousValue: U,currentValue: T,currentIndex: number,array: readonlyT[])=>U,initialValue: U): U
TypeScript Version: 3.9.2/3.8.3/Nightly
Search Terms:
Code
Expected behavior:
The type of
keys.reduce(...)
should be inferred asboolean
Actual behavior:
The type of
keys.reduce(...)
is inferred askeyof T
.Notes
From what I can tell, there are currently 3 definitions for
Array.reduce
.When the
reduce
function is called fromconst result = (item: T) => keys.reduce
TS appears to be inferring the signature of reduce to bereduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
. When the function is inlined, the signature ofreduce
is inferred to bereduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;
.Question:
Is this signature needed?
This signature would seem to satisfy those constraints.
Playground Link:
3.9.2
3.8.3
Nightly
Related Issues:
This issue appears to be similar to #33886, #25454, #33886, #29604
The text was updated successfully, but these errors were encountered: