Skip to content

Overly strict type narrowing in tuple #27557

Closed

Description

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:

Activity

  1. ghost added
    BugA bug in TypeScript
    on Oct 4, 2018
  2. ahejlsberg commented on Oct 5, 2018

    @ahejlsberg
    Member

    Duplicate of #27412.

  3. added
    DuplicateAn existing issue was already created
    and removed
    BugA bug in TypeScript
    on Oct 5, 2018
  4. added a commit that references this issue on Oct 5, 2018
    f5190d1
  5. added a commit that references this issue on Oct 5, 2018
    c080324
  6. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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