Skip to content

Cannot assign array.map(...) to arr2 because array type [1] has an unknown number of elements #6419

@b4nst

Description

@b4nst

reproduced here

// @flow

class Foo {
  bar: number;
}

const arr = [new Foo(), new Foo(), new Foo()];

const arr2: [] = arr.map(a => a.bar);
Cannot assign arr.map(...) to arr2 because array type [1] has an unknown number of elements, so is
incompatible with tuple type [2].

     src/main/test.js
       6│
       7│ const arr = [new Foo(), new Foo(), new Foo()];
       8│
 [2]   9│ const arr2: [] = arr.map(a => a.bar);
      10│

     /private/tmp/flow/flowlib_1af87bb1/core.js
 [1] 248│     map<U>(callbackfn: (value: T, index: number, array: Array<T>) => U, thisArg?: any): Array<U>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions