ajv-validator / ajv-validator/ajv
Define the Record occur typescript error
- Dominant language
- TypeScript
- Stars
- 14.8k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
**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?**
Contributor guide
Assessment
This issue has not been assessed yet.