Skip to content

Array.prototype.flat definitions are inaccurate #29741

Closed
@shicks

Description

@shicks

Code

const x = [1, [[2]]];
const y: never = x.flat();

Expected behavior:
I expect the following error:

Type '(1 | [2])[]' is not assignable to type 'never'.

or with more general types,

Type '(number | number[])[]' is not assignable to type 'never'.

This should actually be pretty easy to implement by simply unwrapping the array type (see link below).

Actual behavior:
I instead see

Type 'any[]' is not assignable to type 'never'.

Playground Link:
Using the current definitions
What I expect should happen

Related Issues:
None found.

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