Closed
Description
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.