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
If we want to validate an object with optional parameters for a spread:
typeHotdog={length: number;topping: string;}functionpatchHotdog(hotdog: Hotdog,patchBody: unknown): Hotdog{ow(patchBody,ow.object.exactShape({length: ow.optional.number,topping: ow.optional.string,}))return{
...hotdog,
...patchBody}// ERROR://TS2322: Type '{ length: number | undefined; topping: string | undefined; }' is not assignable to type 'Hotdog'.// Types of property 'length' are incompatible.// Type 'number | undefined' is not assignable to type 'number'.// Type 'undefined' is not assignable to type 'number'.}
If we want to validate an object with optional parameters for a spread:
This doesn't work, as ow will assert
patchBody
aswhen really we want
Which makes a difference, as js treats undefined value and no key differently when spreading:
Unless I'm missing something, it doesn't look like
ow
provides a way to do this out of the box.In the mean time, I've worked around this by passing in an explicit type argument:
The text was updated successfully, but these errors were encountered: