Double error message when referencing variable of type union of string literals from ambient declaration #63050
Copy link
Copy link
Open
Labels
Domain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingHelp WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
Description
🔎 Search Terms
double error, same message twice, ambient declaration, string literal union
🕗 Version & Regression Information
This changed between versions 3.9.7 and 4.0.5
⏯ Playground Link
💻 Code
declare const x: "a" | "b"
const y: number = x
// ~
// Type 'string' is not assignable to type 'number'.
// Type 'string' is not assignable to type 'number'. (2322)🙁 Actual behavior
You see same error message twice
🙂 Expected behavior
The error message should be the one in 3.9.7 ie...
Type '"a" | "b"' is not assignable to type 'number'.
Type '"a"' is not assignable to type 'number'. (2322)
Or the following message just once also works...
Type 'string' is not assignable to type 'number'. (2322)
Additional information about the issue
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Domain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingHelp WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Activity
Andarist commentedon Jan 26, 2026
The source gets generalized here:
https://github.com/microsoft/typescript-go/blob/2ca325f7c6968077053fbc26302a2dfd44e4903b/internal/checker/relater.go#L4691-L4695
The code is not union-aware and it comes from #38049
AdyaTech commentedon Jan 28, 2026
Hey! I think I figured out why you’re seeing the duplicate error messages.
From what I can tell:
xis a union of string literals ("a" | "b").yis anumber.Now, in updated TypeScript versions, the compiler simplifies
"a" | "b"tostringinternally, which triggers two error messages:Type 'string' is not assignable to type 'number'(general)Type '"a" | "b"' is not assignable to type 'number'(specific literal)However, in TS 3.9.7 it only showed the more specific one, which is why it looked clean.
Fix duplicate error message for literal union types (microsoft#63050)
niranjannnnn55-bot commentedon Mar 21, 2026