Skip to content

Instantly share code, notes, and snippets.

@garbles
Last active March 13, 2017 05:29
Show Gist options
  • Save garbles/686882c6b2199048f61ac6429d738a92 to your computer and use it in GitHub Desktop.
Save garbles/686882c6b2199048f61ac6429d738a92 to your computer and use it in GitHub Desktop.
import {sample, sampleOne, types} from 'babel-plugin-transform-flow-to-gen/api';
import type {Animal, Dog} from './types';
const dogGen = Animal(types.literal('dog'));
const anySpeciesGen = Animal(types.string());
const dog = sampleOne(dogGen);
console.log(dog);
// { "species": "dog", "name": "ahKL9p" }
console.log(Dog());
// { "species": "dog", "name": "1c" }
export type Animal<T> = {
species: T,
name: string
}
export type Dog = Animal<'dog'>;
export type AnySpecies = Animal<string>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment