Skip to content

Instantly share code, notes, and snippets.

@moshest
Created March 29, 2020 14:30
Show Gist options
  • Save moshest/b218db9e1a3a0abffcb7c59c5af0ca05 to your computer and use it in GitHub Desktop.
Save moshest/b218db9e1a3a0abffcb7c59c5af0ca05 to your computer and use it in GitHub Desktop.
Funval demo ts error
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