Skip to content

Conflicting definitions for Set constructor causes unexpected default generic in TS 3.5 #31990

Open
@evmar

Description

@evmar

TypeScript Version: 3.4.5 vs versions after 3.5

Search Terms: set constructor setconstructor unknown

Code

let s = new Set();

Expected behavior:

In TS 3.4: we expect the default chosen param to give us a Set<{}>.
In TS 3.5: we expect a Set<unknown>.
That change was an intended change in TS 3.5.

Or, if Set has a default generic arg, I expect the same default chosen in 3.4 and 3.5.

Actual behavior:

In TS 3.4, this actually was a Set<any>!

It appears there are multiple overloads of the Set constructor.

lib.es2015.collection.d.ts says:

    new <T = any>(values?: ReadonlyArray<T> | null): Set<T>;

while lib.es2105.iterable.d.ts says:

    new <T>(iterable?: Iterable<T> | null): Set<T>;

Note that one has T = any and the other doesn't.

So somehow TS 3.4 vs TS 3.5 decided to change whether to obey the any default, I think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions