Skip to content

Tuple type is inferred from array even after mutable operation on it #4702

@irnc

Description

@irnc

a at the end of following program has tuple type defined as [string, string]

// @flow

const a = ['1', '2'];
const fn = (p: [string, string]) => {
  console.log(p);
};

a.unshift(3);

fn(a);

I would expect a to be inferred as [number, string, string] or Array<string | number>. Seeing tuple of 2 elements was unexpected.

Aforementioned code results in no error, please try it on Try Flow.

On the contrarry fn2(a) as defined below evaluates without errors:

const fn2 = (p: Array<string | number>) => {
  console.log(p);
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Typing: soundnessNo false negatives (type checker claims that there is no error in the incorrect program)Typing: tuplebug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions