Skip to content

Inference fails form unions of arrays of different depths (T[] | T[][]) #1789

@dragomirtitian

Description

@dragomirtitian

Steps to reproduce

declare function flat<T>(args: T[] | T[][]): void;
type Value = 1 | 2
declare const n: Value[] | Value[][]
flat(n)

Behavior with typescript@5.8

Type checks, T is inferred as Value

Behavior with tsgo

We get an error in flat(n):

error TS2345: Argument of type 'Value[][] | Value[]' is not assignable to parameter of type 'Value[][][] | Value[][]'.
  Type 'Value[]' is not assignable to type 'Value[][][] | Value[][]'.
    Type 'Value[]' is not assignable to type 'Value[][][]'.
      Type 'number' is not assignable to type 'Value[][]'.
        Type 'number' is not assignable to type 'Value[][]'.

Metadata

Metadata

Assignees

Labels

Domain: Type CheckingRelated to type checking, grammar checkingType OrderingAn issue related to ordering of types

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions