Skip to content

Instantly share code, notes, and snippets.

@Brettm12345
Created September 20, 2019 08:08
Show Gist options
  • Save Brettm12345/a16ba64f1486802c9e8bd96c913c062b to your computer and use it in GitHub Desktop.
Save Brettm12345/a16ba64f1486802c9e8bd96c913c062b to your computer and use it in GitHub Desktop.
Yup validate function with fp-ts
import { toError } from 'fp-ts/lib/Either';
import { tryCatch } from 'fp-ts/lib/TaskEither';
import { Schema } from 'yup';
const validate = <T extends Schema<any>>(constructor: T) => (input: any) =>
tryCatch<Error, T extends Schema<infer P> ? P : never>(
() => constructor.validate(input),
toError
);
export default validate;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment