Skip to content

Change in inference from tuple to array #1032

Open
@TimMoore

Description

@TimMoore

The following code is accepted by TypeScript tsc 5.8.3 but fails with tsgo as of version 7.0.0-dev.20250603.1:

type IMapEntries<K, V> = [K, V][];

type IKeyValueMap<V> = {
  [key: string]: V;
};

function testFunction<K, V>(initialValues?: IMapEntries<K, V> | IKeyValueMap<V>): void {}

const obj = {
  key1: 'value1',
  key2: 'value2',
  key3: 'value3',
};

testFunction(Object.entries(obj).map(([key, value]) => [key, value]));

https://tsplay.dev/mbb5dm

The error from tsgo is:

test.ts(15,14): error TS2345: Argument of type 'string[][]' is not assignable to parameter of type 'IKeyValueMap<string> | IMapEntries<string, string> | undefined'.
  Type 'string[][]' is not assignable to type 'IKeyValueMap<string> | IMapEntries<string, string>'.
    Type 'string[][]' is not assignable to type 'IMapEntries<string, string>'.
      Type 'string[]' is not assignable to type '[string, string]'.
        Target requires 2 element(s) but source may have fewer.

Seemingly incidental changes such as inlining either of those type definitions into the function signature resolves the error.

This is a simplification of production code using the MobX observable.map function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Type CheckingRelated to type checking, grammar checkingType OrderingAn issue related to ordering of typeswontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions