Closed bradzacher closed 6 months ago
Update: This is a regression in TS5.4
In TS5.3 the emitted .d.ts
file is correct, but in TS5.4 it uses the wrong type names
I've got a repro repo for testing too.
1) clone https://github.com/bradzacher/bug-repros
2) checkout the typescript-dts-emit-bug
branch
3) npm i
4) npm test
--> observe diff
Bisecting it looks like the first release that exhibited this bug was 5.4.0-dev.20240110
(it does not reproduce on 5.4.0-dev.20240109
)
If you hadn't tried it yet, https://www.npmjs.com/package/every-ts can bisect further down from the nightly versions.
Bisecting with every-ts
reveals 4bcbc16cff6c65caf349f1c1df4dc7b6809468ae to be the bad commit (#56087)
Yup - 100% confirmed. 4bcbc16cff6c65caf349f1c1df4dc7b6809468ae only has 4 lines of changes so it's easy to revert locally. If I comment out the 4 lines then it emits the correct output.
I patched #57396 locally and it looks like it fixes the regression
🔎 Search Terms
error "generic type" "requires" "type argument(s)" declaration .d.ts emit
🕗 Version & Regression Information
⏯ Playground Link
bug workbench link
💻 Code
🙁 Actual behavior
The code emitted for
repro.d.ts
isThis code has two type errors (on lines 2-6 and 7-11 respectively):
Note how the generated type uses
TwentyNine
on L2 andTwentyEight
on L7. These are the incorrect types to use (see below)🙂 Expected behavior
The types generate valid code with no semantic errors. For example intellisense reports this type for
bar
which is validNote how this type instead uses
ThirtySix
on L2 andThirtyFive
on L7.Additional information about the issue
Sorry that this example is so goddamn disgusting to look at. This is the name-mangled version of some real code from our codebase. I tried to minimise it but it's all such an intermingled spaghetti mess that I wasn't able to figure out what things I could delete without changing the output.
For context - I am working on upgrading our codebase to TS5.4. When I ran our typecheck CLI I got a number of errors across the codebase. When I opened the files with errors - those errors didn't show up in the IDE. I spent a while pulling my hair out trying to figure out why there was a discrepancy.
The error messages led me back to a monster file which makes use of some really ugly patterns of inferred types from
typeof
s to generate a lot of types. For reference the file itself is >3k LOC and the.d.ts
file it generates is >11k LOC. So so so many anonymous, inferred types.When I opened the
.d.ts
file it was filled with type errors. From what I can tell what's happening is that when you open the files with errors in the IDE then TS uses the.ts
source files for type checking and so it uses the "correct" type for everything. When we run our CLI to do the typecheck it uses project references and so it uses the.d.ts
output instead.Because the
.d.ts
output doesn't match the types TS infers from the.ts
file this causes the discrepancy between the reported errors.I think a most (if not all) of the errors in the
.d.ts
file are variations of the error shown by this repro but it's so hard to know as there are hundreds of them.Note: I didn't write this code and I hate that it exists. I am sorry.