arktypea
arktype10mo ago
L0xus

Narrow type based on another property's value

Hey, I've been using ArkType for a few days now - loving it so far. One thing I'd love to be able to do is narrow a type based on the value of another property in the object. eg.

const myType = type("'string' | 'Color'")

const myValue = type({
  type: myType,
  value: type("'string' | 'string.hex'")
})


given this code, I would want the type of 'value' to change based on the 'type' property. if 'type ' is 'string', then I'd want value to be narrowed to 'string', but if 'type' is 'Color', I'd want it to be narrowed to 'string.hex'. Is there currently a way to do this in the ArkType system?

Many thanks in advance,

Chris
Was this page helpful?