-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Improve error messages for discriminated union incompatible members #62837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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
|
@alpha2420 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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: