这两者之间有什么不同:
type MovieType = {|
+blob?: string,
+name: string,
+url?: string
|};
并且
type MovieType = $Exact<$ReadOnly<{
blob?: string,
name: string,
url?: string
}>>;
?
我想知道flowtype是否根据对象的定义方式而有所不同,或者前者只是后者的语法糖。这两者之间有什么不同:
type MovieType = {|
+blob?: string,
+name: string,
+url?: string
|};
并且
type MovieType = $Exact<$ReadOnly<{
blob?: string,
name: string,
url?: string
}>>;
?
我想知道flowtype是否根据对象的定义方式而有所不同,或者前者只是后者的语法糖。这两种对象类型应该是等效的。
$ReadOnly<T>
使所有属性协变:
$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>
将不精确的对象变为精确的对象:
$Exact<{name: string}>是Object文档中{| name: string |}的同义词。