Skip to content

Regression in array destruction in TypeScript 3.3 #29731

Closed
@sergey-shandar

Description

@sergey-shandar

TypeScript Version: 3.3.1 and 3.4.1

Search Terms:

Code

type ImmutableTuple2 = {
    readonly [0]: number
    readonly [1]: string
} & Iterable<number|string>

const f = <T>(_v: T, _c: (v: T) => void) => {}

const v: ImmutableTuple2 = [4, "hello"]

f(v, ([a, b]) => {
    const _a: number = a // a should be a `number` but it's `number`|`string` in TS 3.3
    const _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

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

Labels

Working as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions