ajv-validator / ajv-validator/ajv

Define the Record occur typescript error

Abierto
#1,995 0 comentarios 0 reacciones 0 asignados Ver en GitHub
typescript
Lenguaje dominante
TypeScript
Estrellas
14.8k
Forks
1k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

8.11.0, yes

**Your typescript code**

```typescript
import type { JSONSchemaType } from 'ajv';

type Level = 0 | 1 | 2;
interface ValidateConfig {
rules: Record;
}

export const schema: JSONSchemaType = {
type: 'object',
required: ['rules'],
properties: {
rules: {
type: 'object',
additionalProperties: {
type: [
{
type: 'number',
enum: [0, 1, 2],
},
{
type: 'array',
minItems: 1,
items: [
{
type: 'number',
enum: [0, 1, 2],
},
{
type: 'object',
},
],
},
],
},
},
},
};
```

**Typescript compiler error messages**

```
Type '{ type: "object"; required: "rules"[]; properties: { rules: { type: "object"; additionalProperties: { type: ({ type: string; enum: number[]; } | { type: string; minItems: number; items: ({ type: string; enum: number[]; } | { ...; })[]; })[]; }; }; }; }' is not assignable to type 'UncheckedJSONSchemaType'.
The types of 'properties.rules' are incompatible between these types.
Type '{ type: "object"; additionalProperties: { type: ({ type: string; enum: number[]; } | { type: string; minItems: number; items: ({ type: string; enum: number[]; } | { type: string; })[]; })[]; }; }' is not assignable to type '{ $ref: string; } | (UncheckedJSONSchemaType, false> & { const?: Record | undefined; enum?: readonly Record<...>[] | undefined; default?: Record<...> | undefined; })'.
Types of property 'additionalProperties' are incompatible.
Type '{ type: ({ type: string; enum: number[]; } | { type: string; minItems: number; items: ({ type: string; enum: number[]; } | { type: string; })[]; })[]; }' is not assignable to type 'boolean | UncheckedJSONSchemaType | undefined'.
Type '{ type: ({ type: string; enum: number[]; } | { type: string; minItems: number; items: ({ type: string; enum: number[]; } | { type: string; })[]; })[]; }' is not assignable to type '{ type: "array"; items: readonly [UncheckedJSONSchemaType & { const?: Level | undefined; enum?: readonly Level[] | undefined; default?: Level | undefined; }, UncheckedJSONSchemaType<...> & { ...; }] & { ...; }; minItems: 2; } & { ...; } & { ...; } & { ...; }'.
Type '{ type: ({ type: string; enum: number[]; } | { type: string; minItems: number; items: ({ type: string; enum: number[]; } | { type: string; })[]; })[]; }' is missing the following properties from type '{ type: "array"; items: readonly [UncheckedJSONSchemaType & { const?: Level | undefined; enum?: readonly Level[] | undefined; default?: Level | undefined; }, UncheckedJSONSchemaType<...> & { ...; }] & { ...; }; minItems: 2; }': items, minItems
```

**Describe the change that should be made to address the issue?**

**Are you going to resolve the issue?**

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.