Skip to content
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

union type no type was matched and no error was reported. #56635

Closed
WangZiChu199910252255 opened this issue Dec 1, 2023 · 4 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@WangZiChu199910252255
Copy link

Use a combined type to define, and a single type will fail all tests, but no error will be reported when combined.

const example1: { A?: string } = { A: '', B: 12 }  // Object literals can only specify known properties, and 'B' is not in type '{ A?: string; }'.
const example2: { A?: string } & { B: number; C: string } = { A: '', B: 12 } // Type '{ A: string; B: number; }' cannot be assigned to type '{ A?: string; } & { B: number; C: string; }'. Property 'C' is missing from type '{ A: string; B: number; }' but is required in type '{ B: number; C: string; }'.
const example3: { A?: string } | ({ A?: string } & { B: number; C: string }) = { A: '' , C:'true'}
@WangZiChu199910252255 WangZiChu199910252255 added the Duplicate An existing issue was already created label Dec 1, 2023
@NWYLZW
Copy link

NWYLZW commented Dec 1, 2023

The example3 looks like the variable assign.

image

@MartinJohns
Copy link
Contributor

Works as expected. Excess property checks do not work for union types, and the object literal is assignable to { A?: string }.

@jcalz
Copy link
Contributor

jcalz commented Dec 1, 2023

Duplicate of #20863, nice that the OP already tagged it as a such when opening the issue 🙃

@fatcerberus
Copy link

Yeah, but it only got tagged as a dupe because the OP used the 9998 issue template - which they apparently didn’t read because this is unrelated and you’re not supposed to post with that template anyway 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

6 participants