isSchemaType()
isSchemaType<
T>(schema,type):schema is SchemaOfType<T> & Schema<any> & { type: SchemaType }
Type guard to check if a schema matches a specific schema type.
Type Parameters
T: T extends SchemaType
Parameters
schema: GenericSchema
The schema to check
type: T
The schema type to check against
Returns: schema is SchemaOfType<T> & Schema<any> & { type: SchemaType }
True if the schema matches the specified type
Since
2.0.0
Example
const schema: GenericSchema = string();
if (isSchemaType(schema, "string")) {
// schema is narrowed to StringSchema (base type, without constraint methods)
console.log(schema.type); // "string"
}