ajv-validator / ajv-validator/ajv

JSONSchema with allOf throws unexpected typescript compiler error

Aperta
#2,227 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
limitation typescript
Lingua principale
TypeScript
Stelle
14.8k
Fork
1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.