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
Typescript infers type number[]for acc and throws this error:
Type 'number[]' is not assignable to type '[number, number][]'.
π Expected behavior
Typescript should infer type [number, number][].
When passing this type explicitely, the code compiles, i.e. it is possible to derive a correct type annotation.
let lst: number[][] = [[0]];
let x = 0;
const coords: [number, number][] = lst.reduce((acc: [number, number][], row, i) => {
let j = 0;
acc.push([i, j]);
return acc;
}, [])
π Search Terms
"type inference reduce" "type inference tuple type"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=3.8.3&q=84#code/DYUwLgBMDOYFwQHYFcC2AjEAnA2gXXwgF4IccAGPPAbgChRIAPYicugYwHtFYIvOsAE2gIcKDNgA0SNJiwE8LGGAB0WEIOTsQACh0BDdu2lZOAd2kBLAJTEAfBADeEFy9quPUcBABWLNu6eLobsKgAOyNAAFjo4ltI+eNbUnoFB6mDIWIgQIXQeAL7S+NZAA
π» Code
π Actual behavior
Typescript infers type
number[]
for acc and throws this error:π Expected behavior
Typescript should infer type
[number, number][]
.When passing this type explicitely, the code compiles, i.e. it is possible to derive a correct type annotation.
https://www.typescriptlang.org/play/?ts=5.6.2&ssl=7&ssc=11&pln=1&pc=1&q=84#code/DYUwLgBMDOYFwQHYFcC2AjEAnA2gXXwgF4IccAGPPAbgChRIAPYicugYwHtFYIvOsAE2gIcKDNgA0SNJiwE8LGGAB0WEIOTsQACh0BDdu1Hi5009gXSsnAO7SAlgEpiAPggBvCN++0f-qHAIACsWNj8A70N2FQAHZGgACx0cB2lgvCdqAIjI9TBkLEQIaLp-AF9pfCcgA
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: