2 ms·
You should be able to add a type requirement and get the error you are expecting. Instead of this: let newThing = { ...thing, propertyName: value } // type
by WorldMaker 10y ago
You should be able to add a type requirement and get the error you are expecting. Instead of this:
let newThing = { ...thing, propertyName: value } // type of newThing would be deduced: TypeOfThing & { propertyName: TypeOfValue }
If you add the type requirement the compiler should balk on the propertyName:
let newThing: TypeOfThing = { ...thing, propertyName: value }
ETA: You'd have the same lack of compiler error if you were instead using:
let newThing = Object.assign({}, thing, { propertyName: value })
Because Object.assign will also build intersection types by default.