Many times I find myself passing in as an arg a certain Shape type but where each key is optional, only at least one is required.
For example:
type Shape = {
+isFetching: boolean,
+errorFetching: null | string
}
type ShapeOpt = {
isFetching?: boolean,
errorFetching?: boolean
}
function set(data: ShapeOpt) {
for (const key in data) {
global[key] = data[key];
}
}
Is there a utility function to convert from Shape to ShapeOpt?
There is a $Shape<Type> helper for generating an object type where each key is optional. But I don't know of a way to say that at least one item is required automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With