ajv-validator / ajv-validator/ajv

JSONSchema with allOf throws unexpected typescript compiler error

Đang mở
#2,227 3 bình luận 0 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

**Ajv options object**
```{}```

```javascript
import {JSONSchemaType} from 'ajv'

type Schema = JSONSchemaType;

type Foo = {
name: 'FOO';
};

type Bar = Foo & {
field: string;
}

const FooSchema: Schema = {
$id: '/foo',
type: 'object',
properties: {
name: {
type: 'string'
}
},
required: []
}

const BarSchema: Schema = {
allOf: [
{ $ref: '/foo' },
{
type: 'object',
properties: {
field: {
type: 'string'
}
},
required: []
}
],
definitions: {
foo: FooSchema
}
}

console.log(BarSchema)
```

[Here](https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbwFIGUDyA5FBjAFgUxAEMAVATzHwF84AzKCEOAciICsA3ZgKG5gvxwcBYgB4SAPjgBeOKkzDCpAeIkBuXv0pwAYhAgzEcYydNnzFy+e7GAdkRD4AXCx1o0zNVe8-ff-wGBQcEhoWbcVBp8AnAAQkRQhnoGAGSINnTA+AA2ACYuAM4wUMC2AOYaVLzYELZFuvqKxC5NRKLJUrIIGQAkwPksAPS0+swANBlaziwQAEZs+Ngw4xlgDJSwWQUu3ab2jjsZplMuzEUl5TymVcZUE8ZQ+ACOAK7AjwMA2gC6EdW19XiUFaLTwSlEQM66WMRGy2TQtBcnyORh6j0RQxGEGYcDuKN2ZhOM3mi2W9zMawgGxgW0OlloWTydKsRLOxVKZSuFhuZjx5ker3e+C+v2uGW+5Ny+AZtmANIBzOMWJcyVaGSqVW4NTqEGy+AAdNkIGUABRA1oASiAA) is the TS Playground

**Validation result, data AFTER validation, error messages**

```
Type '{ allOf: ({ $ref: string; } | { type: "object"; properties: { field: { type: "string"; }; }; required: never[]; })[]; definitions: { foo: { type: "object"; additionalProperties?: boolean | UncheckedJSONSchemaType | undefined; ... 8 more ...; maxProperties?: number | undefined; } & { ...; } & { ...; }...' is not assignable to type 'Schema'.
Type '{ allOf: ({ $ref: string; } | { type: "object"; properties: { field: { type: "string"; }; }; required: never[]; })[]; definitions: { foo: { type: "object"; additionalProperties?: boolean | UncheckedJSONSchemaType | undefined; ... 8 more ...; maxProperties?: number | undefined; } & { ...; } & { ...; }...' is not assignable to type '{ type: "object"; additionalProperties?: boolean | UncheckedJSONSchemaType | undefined; unevaluatedProperties?: boolean | UncheckedJSONSchemaType | undefined; ... 7 more ...; maxProperties?: number | undefined; } & { ...; } & { ...; } & { ...; }'.
Property 'type' is missing in type '{ allOf: ({ $ref: string; } | { type: "object"; properties: { field: { type: "string"; }; }; required: never[]; })[]; definitions: { foo: { type: "object"; additionalProperties?: boolean | UncheckedJSONSchemaType | undefined; ... 8 more ...; maxProperties?: number | undefined; } & { ...; } & { ...; }...' but required in type '{ type: "object"; additionalProperties?: boolean | UncheckedJSONSchemaType | undefined; unevaluatedProperties?: boolean | UncheckedJSONSchemaType | undefined; ... 7 more ...; maxProperties?: number | undefined; }'.
```

**What results did you expect?**
No compilation error

**Are you going to resolve the issue?**
Depends on what the issue is

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.