diff --git a/definitions/npm/flow-enums-runtime_v0.x.x/flow_v0.83.x-/flow-enums-runtime_v0.x.x.js b/definitions/npm/flow-enums-runtime_v0.x.x/flow_v0.83.x-/flow-enums-runtime_v0.x.x.js new file mode 100644 index 0000000000..ab7ad05e23 --- /dev/null +++ b/definitions/npm/flow-enums-runtime_v0.x.x/flow_v0.83.x-/flow-enums-runtime_v0.x.x.js @@ -0,0 +1,17 @@ +declare module 'flow-enums-runtime' { + declare type Members = { +[key: string]: string }; + + declare type EnumPrototype = {| + isValid: (x: $Keys) => boolean, + cast: (x: V) => V | void, + members: () => Array<$Keys>, + getName: (value: string) => string, + |}; + + declare type Enum = {| + (members?: T): {| ...EnumPrototype, ...T |}, + Mirrored: (members: Array<$Keys>) => {| ...Members, ...EnumPrototype |}, + |}; + + declare module.exports: Enum; +} diff --git a/definitions/npm/flow-enums-runtime_v0.x.x/flow_v0.83.x-/test_flow-enums-runtime_v0.x.x.js b/definitions/npm/flow-enums-runtime_v0.x.x/flow_v0.83.x-/test_flow-enums-runtime_v0.x.x.js new file mode 100644 index 0000000000..6e5af73c0b --- /dev/null +++ b/definitions/npm/flow-enums-runtime_v0.x.x/flow_v0.83.x-/test_flow-enums-runtime_v0.x.x.js @@ -0,0 +1,39 @@ +// @flow +import { describe, test } from 'flow-typed-test'; +import flowEnumRuntime from 'flow-enums-runtime'; + +describe('flow-enums-runtime', () => { + test('default function', () => { + const obj = { a: 'a' } + + const res = flowEnumRuntime(obj); + + res.a; + res.isValid('a'); + const valid = res.cast('a'); + // $FlowExpectedError[incompatible-use] + valid.toLowerCase(); + if (valid) { + valid.toLowerCase(); + } + (res.members(): Array<$Keys>); + + // $FlowExpectedError[prop-missing] + res.b; + }); + + test('Mirrored', () => { + const { Mirrored } = flowEnumRuntime; + + const obj = { a: 'b' }; + + Mirrored(([]: Array<$Keys>)); + Mirrored<{| a: 'a', b: 'b' |}>(['a', 'b']); + // $FlowExpectedError[prop-missing] + Mirrored<{| a: 'a', b: 'b' |}>(['a', 'b', 'c']); + // $FlowExpectedError[incompatible-call] + Mirrored(); + // $FlowExpectedError[incompatible-call] + Mirrored<{| a: 'a', b: 'b' |}>([1]); + }); +});