I've been working on creating a simple schema for an array of objects, but TypeScript gave me some trouble with the following code:
import { JSONSchemaType } from 'ajv';
const schema: JSONSchemaType<{ label: string; value: string }[]> = {
type: 'array',
items: {
type: 'object',
required: ['label', 'value'], // Type 'string' is not assignable to type 'never'
properties: {
label: { type: 'string' }, // Property 'nullable' is missing in type '{ type: "string"; }' but required in type '{ nullable: true; const?: never; enum?: readonly string[]; default?: string; }'
value: { type: 'string' }, // Property 'nullable' is missing in type '{ type: "string"; }' but required in type '{ nullable: true; const?: never; enum?: readonly string[]; default?: string; }'
},
},
};
I'm trying to figure out what's causing these errors. If I change the properties to
label: { type: 'string', nullable: true }
, it resolves the second error, but ideally neither property should be nullable.
Thank you!
UPDATE:
TypeScript version: 4.0.3
AJV version: 7.2.3