Add support for $ReadOnly and $Exact
parent
c299ef0f06
commit
08dc16aa4b
|
@ -93,6 +93,14 @@ function shape(params: (?Type)[], resolve: TypeId => Type): ?Type {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function unwrap(params: (?Type)[]): ?Type {
|
||||||
|
invariant(params.length === 1);
|
||||||
|
|
||||||
|
const [type] = params;
|
||||||
|
|
||||||
|
return type ? clone(type) : null;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Object: object,
|
Object: object,
|
||||||
Buffer: buffer,
|
Buffer: buffer,
|
||||||
|
@ -102,4 +110,9 @@ export default {
|
||||||
$ElementType: elemType,
|
$ElementType: elemType,
|
||||||
$NonMaybeType: stripMaybe,
|
$NonMaybeType: stripMaybe,
|
||||||
$Shape: shape,
|
$Shape: shape,
|
||||||
|
$ReadOnly: unwrap,
|
||||||
|
$Exact: unwrap, // TODO: another semantic for exact types?
|
||||||
|
// TODO: $Keys
|
||||||
|
// TODO: $Values
|
||||||
|
// TODO: $Diff
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
type X = {
|
||||||
|
x: string;
|
||||||
|
y: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Y = $Exact<X>;
|
||||||
|
|
||||||
|
type Z = $Exact<{z: string}>;
|
||||||
|
|
||||||
|
export type {Y, Z};
|
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"id": ["exact", "X"],
|
||||||
|
"kind": "record",
|
||||||
|
"fields": [
|
||||||
|
{"name": "x", "value": {"kind": "string"}, "required": true},
|
||||||
|
{"name": "y", "value": {"kind": "boolean"}, "required": true}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": ["exact", "Y"],
|
||||||
|
"kind": "reference",
|
||||||
|
"to": ["exact", "X"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": ["exact", "Z"],
|
||||||
|
"kind": "record",
|
||||||
|
"fields": [
|
||||||
|
{"name": "z", "value": {"kind": "string"}, "required": true}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
type X = {
|
||||||
|
x: string;
|
||||||
|
y: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Y = $ReadOnly<X>;
|
||||||
|
|
||||||
|
type Z = $ReadOnly<{z: string}>;
|
||||||
|
|
||||||
|
export type {Y, Z};
|
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"id": ["readOnly", "X"],
|
||||||
|
"kind": "record",
|
||||||
|
"fields": [
|
||||||
|
{"name": "x", "value": {"kind": "string"}, "required": true},
|
||||||
|
{"name": "y", "value": {"kind": "boolean"}, "required": true}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": ["readOnly", "Y"],
|
||||||
|
"kind": "reference",
|
||||||
|
"to": ["readOnly", "X"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": ["readOnly", "Z"],
|
||||||
|
"kind": "record",
|
||||||
|
"fields": [
|
||||||
|
{"name": "z", "value": {"kind": "string"}, "required": true}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue