Suppose I have the following type:
type MixedArray = Array<number | string>;
And sample data that I'd like to be valid:
[ 'dfdf', 9, 0, 'sdfdsf' ]
How do I create an ajv JSONSchemeType that will validate the expected mixed array?
I have tried the following:
import { JSONSchemaType } from 'ajv';
const Mixed: JSONSchemaType<MixedArray> = {
type: 'array',
items: {
anyOf: [
{ type: 'number' },
{ type: 'string' },
]
}
};
But I receive a typescript error:
Type '{ anyOf: ({ type: "number"; } | { type: "string"; })[]; }' is not assignable to type 'JSONSchemaType<string | number, false>'.
json-schema.d.ts(34, 5): The expected type comes from property 'items' which is declared here on type 'JSONSchemaType<MixedType, false>'