-
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
Array Reduce Typing Error #15071
Comments
When types of "acc" and "d", in this case, differs you can write it as |
Aha, thanks for that, your suggestion does seem to work. I do think I gave it enough information to figure out what I intended though. Changing the |
The issue here is that the type |
Firstly I want to thank both of you for your time and responses. I understood that I am still have an uneasy feeling with this because I feel that a Looking at
Whereas I feel the other definition would be more appropriate:
This may very well be naive, but it seems that if the This seems to have quite a lot in common with #7014 though I note that is to do with swapping the type definitions around, I am not sure if that would be another possible way to solve my perceived issue as well. I have made the change locally in |
TypeScript Version: 2.1.6
Code
Expected behavior:
It should compile.
I cannot see how I can be more specific with these types without changing
initial
to an object, for example.Actual behavior:
It seems to get confused thinking the result of input.reduce would be
(string | number)[]
where it would should be[number, number]
.The error message is:
src/src.ts (73,13): error TS2322: Type '(string | number)[]' is not assignable to type '[number, number]'. Property '0' is missing in type '(string | number)[]'.
The text was updated successfully, but these errors were encountered: