JSONSchemaType requires "required" and "additionalProperties", unless it is oneOf schema
See original GitHub issueWhat version of Ajv are you using? Does the issue happen if you use the latest version? 8.0.1, yes
Ajv options object
{}
Your code
type Test = {
some: string;
other: boolean;
};
const t: JSONSchemaType<Test> = {
type: 'object',
properties: {
other: {
type: 'boolean',
},
some: {
type: 'string',
},
},
};
What results did you expect? Should be a valid type, instead the compiler throws
TS2322: Type '{ type: "object"; properties: { other: { type: "boolean"; }; some: { type: "string"; }; }; }' is not assignable to type 'JSONSchemaType<test, false>'. Type '{ type: "object"; properties: { other: { type: "boolean"; }; some: { type: "string"; }; }; }' is not assignable to type '{ oneOf: readonly JSONSchemaType<test, false>[]; } & { [keyword: string]: any; $id?: string; $ref?: string; $defs?: { [x: string]: JSONSchemaType<Known, true>; }; definitions?: { ...; }; }'. Property 'oneOf' is missing in type '{ type: "object"; properties: { other: { type: "boolean"; }; some: { type: "string"; }; }; }' but required in type '{ oneOf: readonly JSONSchemaType<test, false>[]; }'
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:30 (10 by maintainers)
Top GitHub Comments
if this is strictNullCheck - then yes, it’s required to be true for this type to work correctly. It was in the docs previously but looks like with the site migration it was lost - needs to be added.
Btw, using this type is completely optional - it’s only needed for your validation function to be type guard, but you can also pass type parameter directly to ajv.compile - needs to be better documented.
With version 8.0.3 and TypeScript 4.2.3, I get a wired error
Type 'string' is not assignable to type 'never'
(same as comment https://github.com/ajv-validator/ajv/issues/1521#issuecomment-810432163) if I set the strict mode of TypeScript tofalse
🤔Here an exemple to reproduce the error : https://replit.com/@BenjaminDaniel1/AJV-issue-1521
Does any one has any idea about that ?