Reputation: 73808
I have the following object declaration:
type QueryQuantifierType = {
+max?: number,
+min?: number,
+multiple?: boolean
};
It permits:
{
min: 1
}
{
max: 1
}
{
max: 1,
min: 1
}
{
min: 1,
multiple: true
}
{
max: 1,
multiple: true
}
These are valid values.
However, the problem is that it also permits an empty object.
How to define a Flow type for an object that must have at least one of the properties?
Upvotes: 4
Views: 1365
Reputation: 73808
The only way I have figured out how to do this is using a union of exact objects:
type QuantifierType =
{|
+max: number,
+min?: number,
+multiple?: boolean
|} |
{|
+max?: number,
+min: number,
+multiple?: boolean
|} |
{|
+max?: number,
+min?: number,
+multiple: boolean
|};
Upvotes: 4