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

TS2322 not work on some strange situations #50784

Closed
FlareZh opened this issue Sep 15, 2022 · 2 comments
Closed

TS2322 not work on some strange situations #50784

FlareZh opened this issue Sep 15, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@FlareZh
Copy link

FlareZh commented Sep 15, 2022

Bug Report

πŸ”Ž Search Terms

type or, adding undefined, TS2322

πŸ•— Version & Regression Information

Maybe it is from the beginning

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type A = {
    name: string
}
type B = {
    name: string
    id: number
}

type C = A | B

const a: C = {
    name: '1',
    id: undefined, // expect an error
}

const b: C = {
    name: '1',
    id: undefined, // an ts2322 error
    value: 2,
}

πŸ™ Actual behavior

The var a does not report any error, but the var b report error "Type 'undefined' is not assignable to type 'number'(2322)".
Before v3.7.5, it will report error "Type '{ name: string; id: undefined; value: number; }' is not assignable to type 'C'.
Object literal may only specify known properties, and 'value' does not exist in type 'C'.(2322)" on b.
But I think the error should occur on var a too.

πŸ™‚ Expected behavior

The error reported on b should also be reported on var a.

@MartinJohns
Copy link
Contributor

Excess property checks are not working for unions without a discriminant. See #20863.

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Sep 16, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

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

4 participants