Skip to main content

isBooleanSchema

Determines whether a given JSON schema represents a boolean type (nullable or non-nullable). This is a combined filter that matches both { type: 'boolean' } and { type: ['boolean', 'null'] } schemas.

Signature​

const isBooleanSchema: (schema: UnknownSchema) => schema is BooleanSchema

Parameters​

NameTypeDescription
schema-The JSON schema object to inspect

Returns​

Type-safe boolean indicating whether the schema is a boolean schema (nullable or not)

Examples​

Example 1​

isBooleanSchema({ type: 'boolean' }); // true
isBooleanSchema({ type: ['boolean', 'null'] }); // true
isBooleanSchema({ type: 'string' }); // false

Playground​

isBooleanSchema({ type: 'boolean' }); // true
isBooleanSchema({ type: ['boolean', 'null'] }); // true
isBooleanSchema({ type: 'string' }); // false