Closed
Description
Hi!
TypeScript Version: 3.5.2
Search Terms: destructuring result function generics type loss any
Problem is only with snippet 2, when I get the third parameter with destructuring, the first one became any
instead of the generic type. The problem doesn't show if the generic is explicitly provided. Snippets 1, 3 and 4 works as expected.
Code
function foo<T = {}>(): [T, string, number] {
let a: T;
return [a, 'foo', 2];
}
// 1
const [a, b] = foo();
// a: {}, b: string
// 2
const [x, y, z] = foo();
// x: any, y: string, z: number
// 3
const res = foo();
const [x2, y2, z2] = res;
// x2: {}, y: string, z: number
// 4
const [x3, y3, z3] = foo<{ bar: string }>();
// x3: { bar: string }, y3: string, z: number
Expected behavior:
x
type is {}
Actual behavior:
x
type is any
Related Issues:
Some issues are covering topics that seems related, but I couldn't find one with my specific issue, sorry if there's already a duplicate for this one!
Thanks :)