You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Native API: formatDiagnosticsWithColorAndContext drops related information without a file location #65087
formatDiagnosticsWithColorAndContext, relatedInformation, fileless diagnostic, missing related diagnostic text, diagnosticFormatter
🕗 Version & Regression Information
Reproduced against main at 6161772 using Node.js v24.14.0. The same conditional is still present on current main.
The TypeScript 6.0.3 implementation outputs related diagnostic text outside the if (file) branch; the native API implementation only outputs it inside the location branch.
⏯ Playground Link
Not applicable: this exercises the diagnostic formatting API.
💻 Code
Save as repro.mts at the repository root and run node repro.mts with Node.js 24. This calls the formatter directly with a diagnostic containing a related message without a file location.
Adding fileName: "/project/a.ts" and startPosition: { line: 0, character: 0 } to the related diagnostic makes its text appear.
🙂 Expected behavior
The related explanation should be included even when it has no file location. Only the location heading and source context depend on a location.
Additional information about the issue
In diagnosticFormatter.ts, the call to flattenDiagnosticMessage(related, ...) is inside if (related.fileName && related.startPosition). This also drops message chains on locationless related diagnostics.
The diagnostic response type permits omitted file names and positions. In the 6.0.3 formatter, related message text is emitted independently of the file check.
The reproduction uses constructed diagnostic objects to isolate the formatter behavior. Existing formatter tests cover related information with a location.
I would be happy to submit a focused fix and regression tests once this is triaged.
Activity