You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Partial type does not accept plain empty object literal as a default #9069
The partial type also accepts object literal as a default value since it is an extreme case where all properties were omitted <T>(Partial<T> = {}) => {}
Actual behavior
Flow throws an incompatible type error because the object literal is incompatible with {...T}. It can be circumvented by casting an any type to the object.
This utility converts all of an object or interface's named fields to be optional, while maintaining all the object's other properties (e.g. exactness, variance).
I understand that there could only be an indexed type. Hence empty cannot be used for a partial type.
There is no way to do that currently. What I'm saying is that what we are currently doing is technically correct and safe, however it obviously doesn't align with what people intuitively think should happen, so we should think about it.
Activity
gkz commentedon Aug 16, 2023
Technically you can pass in
emptyas the type argument, andPartial<empty>isempty, and{}is not a valid value foremptyinsonifi commentedon Aug 16, 2023
The documentation:
I understand that there could only be an indexed type. Hence
emptycannot be used for a partial type.gkz commentedon Aug 16, 2023
emptyis a subtype of all types includinginterface {}I agree what you are doing is what seems intuitive however
insonifi commentedon Aug 16, 2023
What do you think is the idiomatic way to handle it, then?
gkz commentedon Aug 16, 2023
There is no way to do that currently. What I'm saying is that what we are currently doing is technically correct and safe, however it obviously doesn't align with what people intuitively think should happen, so we should think about it.