ajv-validator / ajv-validator/ajv

SomeJSONSchema does not accept correct JSONSchemaType object

Đang mở
#1,988 11 bình luận 3 reaction 0 người được giao Xem trên GitHub
limitation typescript
Ngôn ngữ chính
TypeScript
Star
14.8k
Fork
1k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**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**

```ts
interface Body {
data: Record;
}

const bodySchema: JSONSchemaType = {
'$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 | 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 | undefined; unevaluatedProperties?: boolean | UncheckedJSONSchemaType | undefined; ... 7 more ...; maxProperties?: number | undefined; } & { ...; } & { ...; } & { ...; }; }' is not assignable to type 'Partial>'.
      Property 'body' is incompatible with index signature.
        Type '{ type: "object"; additionalProperties?: boolean | UncheckedJSONSchemaType | undefined; unevaluatedProperties?: boolean | UncheckedJSONSchemaType | undefined; ... 7 more ...; maxProperties?: number | undefined; } & { ...; } & { ...; } & { ...; }' is not assignable to type '{ $ref: string; } | (UncheckedJSONSchemaType & { const?: Known | undefined; enum?: readonly Known[] | undefined; default?: Known | undefined; }) | undefined'.
          Type '{ type: "object"; additionalProperties?: boolean | UncheckedJSONSchemaType | undefined; unevaluatedProperties?: boolean | UncheckedJSONSchemaType | 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.