Skip to content

Overly strict type narrowing in tuple #27557

Closed
@westonpace

Description

@westonpace

TypeScript Version: 3.2.0-dev.201xxxxx

Search Terms:
type narrowing tuple
type inference tuple

Code

const x: [number, number] = [0, 0];
if (x[0] === 0) {
    x[0] = -1;
}

Expected behavior:
The code should compile. The above code does compile with typescript@3.0.3.

Actual behavior:

error TS2322: Type '-1' is not assignable to type '0'.

Playground Link: http://www.typescriptlang.org/play/

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions