What version of Ajv are you using? Does the issue happen if you use the latest version?
8.17.1 - currently latest available version
Ajv options object
// not needed, just Typescript Types
JSON Schema
{
"type": "object",
"discriminator": {
"propertyName": "animal"
},
"required": ["animal"],
"oneOf": [
{
"title": "Cat",
"properties": {
"animal": {
"const": "Cat"
},
"food": {
"enum": ["meat", "grass", "fish"],
"type": "string"
}
},
"required": ["food"]
},
{
"title": "Fish",
"properties": {
"animal": {
"const": "Fish"
},
"food": {
"enum": ["insect", "worms"],
"type": "string"
},
"water": {
"enum": ["lake", "sea"],
"type": "string"
}
},
"required": ["food", "water"]
}
]
}
Sample data
// not needed, just Typescript Types
Your code
type AnimalExampleType =
| {
animal: "Cat";
ears: number; // missing in schema intentionally
food: "fish" | "grass" | "meat";
}
| {
animal: "Fish";
food: "insect" | "worms";
water: "lake" | "sea";
};
// should report error in tsc, because 'ears' are missing in 'Cat'
const AnimalExampleSchema_OneOf: JSONSchemaType<AnimalExampleType> = {
type: "object",
discriminator: {
propertyName: "animal",
},
required: ["animal"],
oneOf: [
{
title: "Cat",
properties: {
animal: {
const: "Cat",
},
food: {
enum: ["meat", "grass", "fish"],
type: "string",
},
},
required: ["food"],
},
{
title: "Fish",
properties: {
animal: {
const: "Fish",
},
food: {
enum: ["insect", "worms"],
type: "string",
},
water: {
enum: ["lake", "sea"],
type: "string",
},
},
required: ["food", "water"],
},
],
};
Validation result, data AFTER validation, error messages
// no tsc errors appear, even the 'ears' for 'Cat' are missing
What results did you expect?
tsc to report Type mismatch
What version of Ajv are you using? Does the issue happen if you use the latest version?
8.17.1 - currently latest available version
Ajv options object
// not needed, just Typescript TypesJSON Schema
{ "type": "object", "discriminator": { "propertyName": "animal" }, "required": ["animal"], "oneOf": [ { "title": "Cat", "properties": { "animal": { "const": "Cat" }, "food": { "enum": ["meat", "grass", "fish"], "type": "string" } }, "required": ["food"] }, { "title": "Fish", "properties": { "animal": { "const": "Fish" }, "food": { "enum": ["insect", "worms"], "type": "string" }, "water": { "enum": ["lake", "sea"], "type": "string" } }, "required": ["food", "water"] } ] }Sample data
// not needed, just Typescript TypesYour code
Validation result, data AFTER validation, error messages
// no tsc errors appear, even the 'ears' for 'Cat' are missingWhat results did you expect?
tsc to report Type mismatch