Created
March 29, 2020 14:30
-
-
Save moshest/b218db9e1a3a0abffcb7c59c5af0ca05 to your computer and use it in GitHub Desktop.
Funval demo ts error
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 { Schema, Optional, Or, Type } from 'funval'; | |
const UserSchema = { | |
name: Optional(String), | |
status: Or('active' as 'active', 'suspended' as 'suspended'), | |
}; | |
const validator = Schema(UserSchema); | |
let user: Type<typeof UserSchema>; | |
try { | |
user = validator({ | |
username: 'john1', | |
// @ts-ignore Type '"unregistered"' is not assignable to type '"active" | "suspended"'. | |
status: 'unregistered', | |
}); | |
} catch (err) { | |
console.error(err.message, err.paths); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment