Skip to content

Instantly share code, notes, and snippets.

@garbles
Last active March 10, 2017 20:03
Show Gist options
  • Save garbles/13738ee3368647d84549ba9bdd4b879b to your computer and use it in GitHub Desktop.
Save garbles/13738ee3368647d84549ba9bdd4b879b to your computer and use it in GitHub Desktop.
import {sampleOne} from 'babel-plugin-transform-flow-to-gen/api';
type Person = {
name: string,
age: number
}
function setName(person: Person, name: string): Person {
return {
...person,
name
};
}
// transform creates a static member that can generate function arguments
const argsGen = setName.asGenerator();
// generate a sample
const args = sampleOne(argsGen);
// then you can use the args to call the function
const newPerson = setName(...args);
console.log(args);
// [{ "name": "fjX1", "age": 0 }, "xfwef"]
console.log(newPerson);
// { "name": "xfwef", "age": 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment