Type literals in declaration files are emitted with comment blocks from the wrong source file #58143
Labels
Domain: Comment Emit
The issue relates to the emission of comments when compiling
Needs Investigation
This issue needs a team member to investigate its status.
🔎 Search Terms
"comments", "comment emit", "declaration comments", "inconsistent comments", ".d.ts comment", ".d.ts jsdoc", "wrong file", "crlf"
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/dev/bug-workbench/?noLib=true&esModuleInterop=false&target=8&sourceMap=true&declarationMap=true&inlineSources=true&generateTrace=true&ts=5.4.4#code/PTAEAEBMFMGMBsCGAnRAXAlgewHYC5Q1kBXaAKBAgGcALLAdwFEBbDNCscWhlttaSADEM8aAQBGKAHSQpaKhwgAzEdByJmY0EqxY5CygHlBggMqMAKlOs3bd w6lloADwAOWZGlCxcVb1jiAFagALygAN5koKDAAFRxoADCWMyaON46yKAABm7IWG45oHHA0aD5hQQARNUANGQAvgDcZIrgKqLqmhLS8mQYzB5ekaCBIY3aBcyg1VLAOljVrc7unt6 OP6gLmGR5QCCBOMN5fGJKWlqmZ65AELFpeV3x8ENMeVJr0ENLWRAA
💻 Code
Workbench Repro
🙁 Actual behavior
The emitted
bar.d.ts
declaration file includes the comment on line 17 (preceding theB
property assignment inbar.ts
) above eachprop
signature:Note that the
OFFSET...
comment on line 5 (in its entirety) is necessary to reproduce this behavior. This just so happens to align the start of the comment range for theprop
assignment infoo.ts
(63) one character past the start of theB
assignment's comment range inbar.ts
(62).Strangely, if I remove a single character from line 5 (so that both comment range starts are perfectly aligned), the comment above
B.prop
is omitted, but the others remain:Any other changes to the number of characters preceding the object literal expression in
foo.ts
results in the expectedbar.d.ts
:🙂 Expected behavior
Ideally, the emitted
bar.d.ts
declaration file should include the correct comments for all property signatures:But I understand from the FAQ that might have a performance impact. In that case, I would expect the
bar.d.ts
file to consistently omit comments for type literals defined outsidebar.ts
:In other words, the compiler should handle this corner case where comment positions just happen to align across multiple files. The current behavior can lead to weird declaration file inconsistencies across platforms (due to CR characters potentially aligning/mis-aligning comment ranges on Windows only).
Additional information about the issue
A couple other observations:
/**
) inbar.ts
prop
on line 7 has no effect on the emittedbar.d.ts
foo.ts
is substituted for an expression inbar.ts
(and comment ranges align). For example, here's another repro showing similar behavior whenbar.ts
includes calls to a function (returning an object literal) defined infoo.ts
, and yet another where said function returns a class expression instead.The text was updated successfully, but these errors were encountered: