I have a fairly common use case of typing server responses (specifically graphql responses) that contain many optional properties.
For example:
type Animal = {
kind?: string,
age?: number
}
Where kind and age may or may not be defined for the response. I'd like to use this same type definition for my React components, the difference being kind and age are required properties that I would cover with defaultProps. So my React component might look like this:
type Props = {
kind: string,
age: number
}
class Animal extends React.Component<Props> {
static defaultProps = {
kind: 'dog',
age: 2
}
...
}
is my only option to rewrite the entire type definition of Animal, minus the ? syntax? Or is there a way to tell flow that I want to use the Animal type, but make all properties required properties?
You can do an opposite thing
$Shape works great! Why isn't it documented?
@mrkev Do you know why no one from PRs with docs for $Shape does not merged?
no idea, maybe it fell of the radar ¯\_(ツ)_/¯
Most helpful comment
You can do an opposite thing
try