diff --git a/src/collector/globals.js b/src/collector/globals.js index e5501e8..0f3f7bd 100644 --- a/src/collector/globals.js +++ b/src/collector/globals.js @@ -4,18 +4,21 @@ import {invariant} from '../utils'; import type {Type, TypeId} from '../types'; import * as t from '../types'; +// Object. function object(params: (?Type)[]): ?Type { invariant(params.length === 0); return t.createMap(t.createMixed(), t.createMixed()); } +// Buffer. function buffer(params: (?Type)[]): ?Type { invariant(params.length === 0); return t.createReference(['Buffer']); } +// Array and $ReadOnlyArray. function array(params: (?Type)[]): ?Type { invariant(params.length === 1); invariant(params[0]); @@ -23,6 +26,7 @@ function array(params: (?Type)[]): ?Type { return t.createArray(t.clone(params[0])); } +// $ElementType and $PropertyType. function elemType(params: (?Type)[], resolve: TypeId => Type): ?Type { invariant(params.length === 2); @@ -45,6 +49,7 @@ function elemType(params: (?Type)[], resolve: TypeId => Type): ?Type { return field ? t.clone(field.value) : null; } +// $NonMaybeType. function stripMaybe(params: (?Type)[], resolve: TypeId => Type): ?Type { invariant(params.length === 1); @@ -62,6 +67,7 @@ function stripMaybe(params: (?Type)[], resolve: TypeId => Type): ?Type { return t.clone(maybe.value); } +// $Shape. function shape(params: (?Type)[], resolve: TypeId => Type): ?Type { invariant(params.length === 1); @@ -84,6 +90,7 @@ function shape(params: (?Type)[], resolve: TypeId => Type): ?Type { return t.createRecord(fields); } +// $Exact and $ReadOnly. function unwrap(params: (?Type)[]): ?Type { invariant(params.length === 1); @@ -92,6 +99,7 @@ function unwrap(params: (?Type)[]): ?Type { return type ? t.clone(type) : null; } +// $Keys. function keys(params: (?Type)[], resolve: TypeId => Type): ?Type { invariant(params.length === 1); @@ -113,6 +121,7 @@ function keys(params: (?Type)[], resolve: TypeId => Type): ?Type { return t.createUnion(variants); } +// $Values. function values(params: (?Type)[], resolve: TypeId => Type): ?Type { invariant(params.length === 1); @@ -135,6 +144,7 @@ function values(params: (?Type)[], resolve: TypeId => Type): ?Type { return t.createUnion(variants); } +// $Diff. function diff(params: (?Type)[], resolve: TypeId => Type): ?Type { invariant(params.length === 2);