hyperjump-io/json-schema

`JsonSchema` `boolean` type

Closed this issue · 5 comments

Is there a reason why theJsonSchema type has a boolean in its union type? As far as I'm aware, booleans are not valid JSON schemas.

export type JsonSchema = boolean | {

A boolean is a valid JSON Schema since draft-06. You can use a boolean anywhere a schema is expected.

Hmm, this union is presenting a few typescript related issues to me with "type boolean is not assignable to object" and I'm sure my schemas will never be booleans. Would you be willing to accept a PR that exports a subtype for the object? E.g.

export type JsonSchemaObject = {}
export type JsonSchema = boolean | JsonSchemaObject

Found a way:

type JsonSchemaObject = Exclude<JsonSchema, boolean>;

That's a great solution.

Yeah, but it's only a temporary solution of course. I will make my code work with boolean schemas.