Skip to content

Interdependent attributes #692

Answered by ssalbdivad
techpet asked this question in Q&A
Mar 23, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Unfortunately, this is not currently possible via syntax alone. You'd have to use a narrowing function type for the object and compare the properties:

const check = type([
    {
        a: "0<integer<10",
        b: "0<integer<10"
    },
    "=>",
    ({ a, b }, problems) =>
        a < b || !problems.mustBe("an object with a less than b")
])

There is an issue #485 in the backlog to support these kinds of relative comparisons. The more feedback we get on it, the sooner we can prioritize it!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@techpet
Comment options

Answer selected by ssalbdivad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants