-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TypeScript 2.5 not inferring return type of reduce #19823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think the problem is that |
Thanks for the quick reply, that was my best guess too. Specifying the type on |
Similar problem with reducing objects to array. Even specifying type on initialValue doesn't communicate to TS that I'm trying to produce an array.
The last line throws "[ts] Property 'map' does not exist on type '{}'." |
@Vandivier That's not a complete example -- most of the identifiers in that code sample have no definition. When I add |
@Andy-MS I explicitly said my problem was "reducing objects to array" arroResponses is an array of objects. In fact, it is an array of HTTP responses with different shapes. Clearly You can see Clearly the return type should be |
@Vandivier Thanks, created an issue at #25454. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.7.0-dev.201xxxxx
Code
This is a (reasonably) minimal example of the code I'm compiling. My actual function is filtering
entries
before reconstructing the object.Note that the above code requires some options to use
Object.entries
and so you can reproduce the same error with the following code snippet if desired.Expected behavior:
In TypeScript 2.4.2 the constant
rv
is correctly inferred to be of type{ [key: string]: V }
but it does not seem to be in TypeScript 2.5.3.Actual behavior:
rv
is inferred to be of type{}
.It doesn't seem like the definition of
reduce
has changed between versions. VSCode is jumping to this signature ofreduce
.reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
Obviously I can specify the return value of my function
foo
as I have and everything works, but previously I did not need to as it was correctly inferred.The text was updated successfully, but these errors were encountered: