Skip to content

Instantly share code, notes, and snippets.

@iamdustan
Created November 12, 2015 04:29
Show Gist options
  • Save iamdustan/6856f88761e70b0f7dad to your computer and use it in GitHub Desktop.
Save iamdustan/6856f88761e70b0f7dad to your computer and use it in GitHub Desktop.
/* @flow */
type Auth = {
username: string;
password: string;
}
type Auth2 = {
username: string;
}
type AuthKeys = $Keys<Auth>; // make an enum type, with unknown key set
type ReduxFormOptions<T> = {
fields: Array<$Keys<T>>;
onSubmit?: (values:T, dispatch:Function) => ?Promise<?Object>;
};
type ReduxForm<T> = (opts:ReduxFormOptions<T>) => void;
// can I declare the paremeterized type at consumption time?
// there is one reduxForm function for the app, which should
// be paramterized when used.
// something like:
//
// const AuthForm<Auth> = reduxForm(...);
const reduxForm:ReduxForm = (options) => {};
const AuthForm = reduxForm({
fields: ['username', 'password'],
onSubmit(values, dispatch) {
dispatch(authAction(values));
}
})
const AuthForm2 = reduxForm({
fields: ['username', 'password'],
onSubmit(values:Auth2, dispatch) {
dispatch(authAction(values));
}
})
const authAction = (auth:Auth) => auth;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment