Skip to content

SomeJSONSchema does not accept correct JSONSchemaType object #1988

Open
@m-radzikowski

Description

What version of Ajv are you using? Does the issue happen if you use the latest version?

Latest: 8.11.0

Ajv options object

not applicable - errors with TS types

Your code

interface Body {
    data: Record<string, unknown>;
}

const bodySchema: JSONSchemaType<Body> = {
    '$schema': 'https://json-schema.org/draft/2020-12/schema',
    type: 'object',
    properties: {
        data: {
            type: 'object',
        },
    },
    required: ['data'],
};

export const eventSchema: SomeJSONSchema = {
    '$schema': 'https://json-schema.org/draft/2020-12/schema',
    type: 'object',
    properties: {
        body: bodySchema,
    },
    required: ['body'],
};

TS error:

TS2322: Type '{ $schema: string; type: "object"; properties: { body: { type: "object"; additionalProperties?: boolean | UncheckedJSONSchemaType<unknown, false> | undefined; unevaluatedProperties?: boolean | ... 1 more ... | undefined; ... 7 more ...; maxProperties?: number | undefined; } & { ...; } & { ...; } & { ...; }; }; requi...' is not assignable to type 'SomeJSONSchema'. 
  Types of property 'properties' are incompatible. 
    Type '{ body: { type: "object"; additionalProperties?: boolean | UncheckedJSONSchemaType<unknown, false> | undefined; unevaluatedProperties?: boolean | UncheckedJSONSchemaType<unknown, false> | undefined; ... 7 more ...; maxProperties?: number | undefined; } & { ...; } & { ...; } & { ...; }; }' is not assignable to type 'Partial<UncheckedPropertiesSchema<{ [key: string]: Known; }>>'. 
      Property 'body' is incompatible with index signature. 
        Type '{ type: "object"; additionalProperties?: boolean | UncheckedJSONSchemaType<unknown, false> | undefined; unevaluatedProperties?: boolean | UncheckedJSONSchemaType<unknown, false> | undefined; ... 7 more ...; maxProperties?: number | undefined; } & { ...; } & { ...; } & { ...; }' is not assignable to type '{ $ref: string; } | (UncheckedJSONSchemaType<Known, false> & { const?: Known | undefined; enum?: readonly Known[] | undefined; default?: Known | undefined; }) | undefined'. 
          Type '{ type: "object"; additionalProperties?: boolean | UncheckedJSONSchemaType<unknown, false> | undefined; unevaluatedProperties?: boolean | UncheckedJSONSchemaType<unknown, false> | undefined; ... 7 more ...; maxProperties?: number | undefined; } & { ...; } & { ...; } & { ...; }' is not assignable to type '{ $ref: string; }'. 
            Types of property '$ref' are incompatible. 
              Type 'string | undefined' is not assignable to type 'string'. 
                Type 'undefined' is not assignable to type 'string'.

What results did you expect?

SomeJSONSchema should be possible to be composed of other valid schema objects.

Are you going to resolve the issue?

It can be over my possibilities.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions