0

Not a duplicate. Variations not finite. Overloads not possible, as mentioned in my original question. (any number can be provided into the component by the user of the component)

How can I prevent one value being outside the scope of a safe range, when all 3 values are provided at function call?

interface FooParams {
  minVal: number
  maxVal: number
  initVal?: number
  ...
}

const Foo = ({minVal, maxVal, initVal=minVal ... }: FooParams) => { ... }

<Foo minVal={10} initVal={9} maxVal={20} ... />

(Other SO solutions suggested using overloads, but those were for a small number of finite options.)

sashaikevich
  • 167
  • 13

0 Answers0