Created
September 20, 2019 08:08
-
-
Save Brettm12345/a16ba64f1486802c9e8bd96c913c062b to your computer and use it in GitHub Desktop.
Yup validate function with fp-ts
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 { 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