Native API: formatDiagnosticsWithColorAndContext drops related information without a file location
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #65112 by @timurzvural — closed without merging
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- api
Research direction
The bug is in packages/typescript/src/api/diagnosticFormatter.ts, where the flattenDiagnosticMessage(related, ...) call sits inside an if (related.fileName && related.startPosition) branch. Run the reproduction script from the issue to confirm the related text is missing. Done means the related text appears for locationless diagnostics, while the location heading and source context stay conditional on a file. Add a regression test next to the existing formatter tests.
Written by the indexing model from the issue text.
Description
🔎 Search Terms
formatDiagnosticsWithColorAndContext, relatedInformation, fileless diagnostic, missing related diagnostic text, diagnosticFormatter
🕗 Version & Regression Information
Reproduced against main at 6161772c1370bdd4a82f808e6823bd755eb1870d 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.
import { formatDiagnosticsWithColorAndContext } from "./packages/typescript/src/api/diagnosticFormatter.ts";
const host = {
getCurrentDirectory: () => "/project",
getCanonicalFileName: (name: string) => name,
getNewLine: () => "\n",
};
const output = formatDiagnosticsWithColorAndContext([{
category: 1,
code: 2322,
pos: 0,
end: 0,
text: "Primary error.",
relatedInformation: [{
category: 3,
code: 9999,
pos: 0,
end: 0,
text: "This related explanation must remain visible.",
}],
}], host);
console.log(JSON.stringify(output.replace(/\x1b\[[0-9;]*m/g, "")));
🙁 Actual behavior
The related explanation disappears:
"error TS2322: Primary error.\n"
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.
- Dominant language
- Go
- Stars
- 112k
- Forks
- 15.4k
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 136
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/TypeScript
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
microsoft/TypeScript#65290 ·
Maintainers usually reply within 1 day
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'May be free again A pull request for this issue was closed without being merged. OpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/TypeScript#64758 ·
Maintainers usually reply within 1 day
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`Possibly taken @rajnish-verma-22172 claimed this 14 days ago. OpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
microsoft/TypeScript#64742 · 1 comment ·
Maintainers usually reply within 1 day
-
Non-enum CLI options with multiple values separated by comma and space aren't whitespace trimmedPossibly taken @RyanCavanaugh claimed this 28 days ago. OpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microsoft/TypeScript#64618 · 1 assignee ·
Maintainers usually reply within 1 day
-
TypeScript 7 VS Code extension: a workspace "typescript" 7.x package is not detected, only "@typescript/native-preview", which is no longer publishedMay be free again @jakebailey claimed this 28 days ago, and no pull request is open. OpenNeeds Investigation
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
microsoft/TypeScript#64565 · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
All issues in microsoft/TypeScript
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
component/tests needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
NVIDIA/nodewright#967 ·
Maintainers usually reply within 1 day
-
apm:ecosystem needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
DataDog/dd-trace-go#5815 ·
Maintainers usually reply within 2 days
-
Build releases with Go 1.26.10+ for CVE-2026-111943 (eMudhra intermediate CA compromise)Possibly taken @zoezhangmattr claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
auth0/terraform-provider-auth0#1778 ·
Maintainers usually reply within 2 days
-
area:sampler tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
jmbarzee/temporal-architect#302 ·
Maintainers usually reply within 1 day