Closed
Description
openedon Feb 22, 2022
Bug Report
π Search Terms
spread
spread operator
spread any
spread object assign
π Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about the spread operator
β― Playground Link
Playground link with relevant code
π» Code
const x: any = { a: 5 }
interface I {
b?: string
}
let spread: I;
spread = {
...x,
b: 5
}
π Actual behavior
Type mismatch is missed after use of spread operator.
π Expected behavior
I expect a "Type 'number' is not assignable to type 'string | undefined'.(2322)" error for b: 5
.
Similar bug #46128 indicates that after spread the type is not kept.
The main difference between the bugs is that in this case, the type is declared beforehand.
Edit: removed a line of code and changed some wording to make things clearer
Activity