How can I define a TypeScript interface with the additional constraint that entries in the 'required' field must be keys of the 'properties' field?
interface ObjectSchema {
properties: Record<string, any>;
required: Array<string>;
}
An example of a correctly typed object would be:
let schemaA = {
properties: {
foo: {},
bar: {},
},
required: ["foo"]
}
An example of an incorrectly typed object would be:
let schemaA = {
properties: {
foo: {},
bar: {},
},
required: ["baz"] // "baz" is not a key in 'properties'.
}