-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Incorrect return type for Array.prototype.reduce() #21061
Comments
Since acc (string) is assignable to curItem (C1 | string) typescript cannot tell which overload of reduce you want to use. You can specify this with: |
Thanks for your help. Using I do, however, have some questions about your statements above:
|
this is caused by the overload of reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; since I need to remove it and see what breaks :) |
Duplicate of #7014? |
thanks @yortus |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
The TypeScript compiler thinks the type of the instances.reduce() call below is
C1 | string
. I believe the return type should bestring
.Code
Expected behavior:
I would expect the above code to compile without errors. If I use the Lodash's version of
reduce()
(_.reduce()
) it compiles successfully.Actual behavior:
The assignment of the
result
variable results in "error TS2322 Type 'ItemType' is not assignable to type 'string'. Type 'C1' is not assignable to type 'string'." When evaluating the type of theinstances.reduce()
expression, it isC1 | string
. I would expect it to be juststring
.The text was updated successfully, but these errors were encountered: