Is there any difference between:
type MovieType = {|
+blob?: string,
+name: string,
+url?: string
|};
and
type MovieType = $Exact<$ReadOnly<{
blob?: string,
name: string,
url?: string
}>>;
?
I am wondering if flowtype is treating objects differently depending on how they are defined or if the former is just a syntactic sugar for the latter.
Those two object types should be equivalent.
$ReadOnly<T>
makes all the properties covariant:
$ReadOnly is a type that represents the read-only version of a given object type T. A read-only object type is an object type whose keys are all read-only.
This means that the following 2 types are equivalent:
type ReadOnlyObj = { +key: any, // read-only field, marked by the `+` annotation }; type ReadOnlyObj = $ReadOnly<{ key: any, }>;
$Exact<T>
takes an inexact object and makes it exact:
$Exact<{name: string}> is a synonym for {| name: string |} as in the Object documentation.
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