Skip to main content

isObjectConstraint()

isObjectConstraint<T>(schema): schema is ObjectConstraint<T>

Type guard for ObjectConstraint. Checks that the schema is an object type and has constraint methods.


Type Parametersโ€‹

T: T extends Record<string, GenericSchema> = Record<string, GenericSchema>โ€‹


Parametersโ€‹

schema: GenericSchemaโ€‹

The schema to check


Returns: schema is ObjectConstraint<T>โ€‹

True if the schema is an ObjectConstraint with constraint methods


Sinceโ€‹

2.0.0


Exampleโ€‹

const schema = object({ name: string() }).minKeys(1);
if (isObjectConstraint(schema)) {
// schema is narrowed to ObjectConstraint
schema.maxKeys(5); // constraint methods available
}