is
Checks if the input matches the scheme.
By using a type predicate, this function can be used as a type guard.
const result = v.is<TSchema>(schema, input);
Generics
TSchemaextends BaseSchema<unknown, unknown, BaseIssue<unknown>>
Parameters
schemaTSchemainputunknown
Explanation
is does not modify the input. Therefore, transformations have no effect and unknown keys of an object are not removed. That is why this approach is not as safe and powerful as parse and safeParse.
Returns
resultboolean
Example
The following example show how is can be used.
const EmailSchema = v.pipe(v.string(), v.email());
const data: unknown = 'jane@example.com';
if (v.is(EmailSchema, data)) {
const email = data; // string
}
Related
The following APIs can be combined with is.
Schemas
any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, map, nan, never, nonNullable, nonNullish, nonOptional, null, nullable, nullish, number, object, objectWithRest, optional, picklist, promise, record, set, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void
Methods
assert, config, fallback, keyof, message, omit, partial, pick, pipe, required, unwrap
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/is/