question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
evmarcommented, Jul 25, 2019

Circling back on this – I think maybe I failed to communicate the bug here.

In practice, TS3.4 => TS3.5 changed what new Set() gives you, from Set<any> to Set<unknown>. (That is too late to undo, though massively annoying for us to upgrade through.)

But the actual bug here is that I think you didn’t change the definition of Set! It still says any in the typings, something else must be going wrong.

0reactions
evmarcommented, Jun 23, 2019

Just to restate, what I am concerned about here is whether “new Set()” is supposed to give you a Set<any> or a Set<unknown>, given the conflicting definitions in the typings.

I believe the intention was for 3.5 change it to <unknown> and for that to break apps – that is at least what 3.5 did in practice – but I think the resolution of this bug is to make the typings express that intent more clearly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Constructor of a generic class cannot be assigned to ... - GitHub
IIUC, the compiler is not able to treat DefaultCrudRepository as a generic constructor, instead if specializes the constructor function too ...
Read more >
Documentation - Classes - TypeScript
Constructors can't have return type annotations - the class instance type is always what's returned. Super Calls. Just as in JavaScript, if you...
Read more >
Groovy Language Documentation
Default conflict resolution; User conflict resolution. Runtime implementation of traits ... List , as Groovy doesn't define its own collection classes.
Read more >
Google C++ Style Guide
The goal of this guide is to manage this complexity by describing in detail the dos and don'ts of writing C++ code ....
Read more >
Changelog - Cypress Documentation
Fixed a regression introduced in the Electron browser in Cypress 10.8.0 where the CYPRESS_EVERY_NTH_FRAME environment variable was not being set appropriately ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found