Possibility of undefined
from optional properties is not honoured in spread
#35983
Labels
Unactionable
There isn't something we can do with this issue
TypeScript Version: 3.6.3
Search Terms: spread optional undefined object properties property
Code
Here's an example of spreading an object with optional properties:
The above example makes sense. However, an optional property does not only mean "this property may not exist" (
{}
)—it also means "this property may exist with a value ofundefined
" ({ a: undefined }
). (Related: #13195.)As a result of this, the type information may mismatch the actual types at runtime:
… which could result in runtime exceptions:
Ideally optional properties would only mean "this property may not exist" (#13195), in which case the existing behaviour with spreading makes sense. However, in the interim, perhaps the behaviour of spreading should be changed?
Extracted from #13195 (comment)
Also potentially related: #31025
The text was updated successfully, but these errors were encountered: