Skip to content

TS2322 not work on some strange situationsΒ #50784

Closed
@FlareZh

Description

@FlareZh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions