This repository was archived by the owner on Sep 1, 2026. It is now read-only.
Clarification on Set<unknown> default behavior in JS/JSDoc files vs older TS behavior #4750
Unanswered
SIDDHARTH M.S (Siddharth-M-S)
asked this question in
Q&A
Replies: 1 comment
|
Yes, this was specifically because defaults in JS were actually "any", so those unannotated sets could actually be used anywhere. The same applied to any other generics with unconstrained type parameters. The new implementation rewrites the JSDoc into actual TS annotations that the checker treats as TS, and so this special case does not exist. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I came across discussion #2355 regarding Set and JSDoc type checking.
In older TS versions, const set = new Set() in JS files inferred Set, which allowed passing it into a function expecting Set. Modern TS / tsgo defaults unspecified generics in JS files to unknown (Set), causing ts(2345) assignability errors unless explicitly typed.
Is specifying the type parameter explicitly (e.g., new Set() or JSDoc annotation Type (@type) {Set}) the recommended long-term pattern for JS/JSDoc codebases going forward?
All reactions