Skip to content

Inference to Iterable<[K, V]> | undefined fails #40587

Closed
@sandersn

Description

@sandersn

Regression in 4.1, found in adone on DT.

declare class DMap<K, V>  {
    constructor(iterable: Iterable<[K, V]> | undefined);
}
new DMap([["1", 2]])

Expected behavior:

K=string, V=number, no error

Actual behavior:
K=string | number, V=string | number, "(string | number)[][] is not assignable to to parameter of type Iterable<[string | number, string | number]>."

Removing undefined makes inference work; the actual workaround I used for adone was to split a constructor with optional parameters into 3 overloads.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions