ajv-validator / ajv-validator/ajv

JSONSchema with allOf throws unexpected typescript compiler error

Ouverte
#2,227 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
limitation typescript
Langage dominant
TypeScript
Étoiles
14.8k
Forks
1k
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.