-
Hello, is would like to create a type that is required based on the value of a different type. in JSON schema you could do this like so: x: {
type: 'object',
properties: {
value: {type: 'boolean'},
range: {type: 'integer', multipleOf: 5, minimum: 0, maximum: 60}
},
if: {
properties: {
value: {const: true}
}
},
then: {required: ['range']}
} In typia, to the best of my ability I was able to create something similar using unions x: { value: false; range?: number } | { value: true; range: number } But this is not the same, the generated json-schema will be a is this at all possible with typia? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Not possible, because TypeScript does not have the if condition type spec. Instead, the union ( |
Beta Was this translation helpful? Give feedback.
Not possible, because TypeScript does not have the if condition type spec.
Instead, the union (
oneOf
) type will cover what you want.