Coverage
TypeSchema supports all major schema validation libraries:
Project | Popularity | wrap | validate | assert | Infer | InferIn | Example schema |
---|---|---|---|---|---|---|---|
zod (opens in a new tab) | ✅ | ✅ | ✅ | ✅ | ✅ | z.string() | |
yup (opens in a new tab) | ✅ | ✅ | ✅ | ✅ | ✅ | string() | |
joi (opens in a new tab) | ✅ | ✅ | ✅ | ❌ | ❌ | Joi.string() | |
ajv (opens in a new tab) | ✅ | ✅ | ✅ | ❌ | ❌ | {type: "string"} | |
superstruct (opens in a new tab) | ✅ | ✅ | ✅ | ✅ | ❌ | string() | |
io-ts (opens in a new tab) | ✅ | ✅ | ✅ | ✅ | ✅ | t.string | |
ow (opens in a new tab) (^0.28.2) | ✅ | ✅ | ✅ | ✅ | ✅ | ow.string | |
typia (opens in a new tab) | ✅ | ✅ | ✅ | ✅ | ✅ | typia.createAssert<string>() | |
valibot (opens in a new tab) | ✅ | ✅ | ✅ | ✅ | ✅ | string() | |
typebox (opens in a new tab) | ✅ | ✅ | ✅ | ✅ | ✅ | Type.String() | |
deepkit (opens in a new tab) | ✅ | ✅ | ✅ | ❌ | ❌ | typeOf<string>() | |
effect (opens in a new tab) | ✅ | ✅ | ✅ | ✅ | ✅ | S.string | |
runtypes (opens in a new tab) | ✅ | ✅ | ✅ | ✅ | ✅ | String | |
arktype (opens in a new tab) | ✅ | ✅ | ✅ | ✅ | ✅ | type('string') |
Custom validations are also supported:
export function assertString(data: unknown): string {
if (typeof data !== 'string') {
throw new Error('Expected a string, got: ' + data);
}
return data;
}
await validate(assertString, '123'); // {data: '123'}
await validate(assertString, 123); // {issues: [`ValidationIssue`]}
await assert(assertString, '123'); // '123'
await assert(assertString, 123); // throws `AggregateError`