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
{{ message }}
Repository navigation
Regression in array destruction in TypeScript 3.3 #29731
typeImmutableTuple2={readonly[0]: numberreadonly[1]: string}&Iterable<number|string>constf=<T>(_v: T,_c: (v: T)=>void)=>{}constv: ImmutableTuple2=[4,"hello"]f(v,([a,b])=>{const_a: number=a// a should be a `number` but it's `number`|`string` in TS 3.3const_b: string=b// b should be a `string` but it's `number`|`string` in TS 3.3})
Expected behavior:
No compilation errors. (TypeScript 3.2)
Actual behavior:
TypeScript 3.3.1 and up
src/test.ts:11:11 - error TS2322: Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
11 const _a: number = a
~~
src/test.ts:12:11 - error TS2322: Type 'string | number' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
12 const _b: string = b
~~
Found 2 errors
typeImmutableTuple2={readonly[0]: numberreadonly[1]: string}&Iterable<number|string>constf=([a,b]: ImmutableTuple2)=>{const_a: number=a// a should be a `number` but it's `number`|`string` in TS 3.3const_b: string=b// b should be a `string` but it's `number`|`string` in TS 3.3}
We no longer recognize "pseudo-tuples" like ImmutableTuple2 and given the intrinsic support I don't think adding more complexity in this area is worth it. So, I'm closing this issue.
Activity
sergey-shandar commentedon Feb 4, 2019
Simplified code
sergey-shandar commentedon Feb 4, 2019
Workaround # 1
Workaround # 2
sergey-shandar commentedon Mar 30, 2019
The bug is also in TypeScript 3.4.1.
vladbarosan commentedon Apr 2, 2019
Anders Hejlsberg (@ahejlsberg) is there any expected release when this to be fixed ?
ahejlsberg commentedon Jun 7, 2019
Starting with TypeScript 3.4 we have proper support for
readonlyarrays and tuples (see #29435). The original example can now be written:We no longer recognize "pseudo-tuples" like
ImmutableTuple2and given the intrinsic support I don't think adding more complexity in this area is worth it. So, I'm closing this issue.