Last active
March 10, 2017 20:03
-
-
Save garbles/13738ee3368647d84549ba9bdd4b879b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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