Reputation: 19967
I'm wondering if there is another way to write a maybe type.
type Error = ?{name: string, message:string}
type Error = {name: string, message:string} | null
The above isn't the same since the undefined
case isn't allowed in the second definition, but it is in the first. (source)
However, the below doesn't work.
type Error = {name: string, message:string} | null | undefined
Is there another way to represent a maybe type without using the ?
prefix?
Upvotes: 0
Views: 46
Reputation: 37938
In Flow the type of undefined
is void
, so:
type Error = {name: string, message:string} | null | void
Upvotes: 2
Reputation: 19967
This works!
type Error2 = {name: string, message:string} | null | typeof undefined
Upvotes: 0