Skip to content

Improve error messages for discriminated union incompatible members#62837

Closed
alpha2420 wants to merge 5 commits intomicrosoft:mainfrom
alpha2420:main
Closed

Improve error messages for discriminated union incompatible members#62837
alpha2420 wants to merge 5 commits intomicrosoft:mainfrom
alpha2420:main

Conversation

@alpha2420
Copy link
Copy Markdown

Fixes #62737

When assigning objects with wider discriminator unions to discriminated union types, TypeScript now identifies the actual incompatible types from the source union, rather than showing a misleading error about a compatible type.

Before: Type '"foo"' is not assignable to type '"bar"'

After: The type(s) '"baz"' are not present in the discriminator 'discriminator' of the target.

This change:

  • Adds detection for discriminated union assignment errors
  • Reports which specific types from the source are missing in the target
  • Includes the discriminator property name in the error message
  • Adds comprehensive test cases

Fixes microsoft#62737

When assigning objects with wider discriminator unions to discriminated
union types, TypeScript now identifies the actual incompatible types from
the source union, rather than showing a misleading error about a compatible
type.

Before: Type '"foo"' is not assignable to type '"bar"'
After:  The type(s) '"baz"' are not present in the discriminator 'discriminator' of the target.

This change:
- Adds detection for discriminated union assignment errors
- Reports which specific types from the source are missing in the target
- Includes the discriminator property name in the error message
- Adds comprehensive test cases
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Dec 4, 2025
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Dec 4, 2025
@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
@typescript-bot
Copy link
Copy Markdown
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Show incompatible union members in discriminated union discriminator errors

3 participants