object-shape-tester - v5.1.6
    Preparing search index...

    Function numericRange

    • Define a shape part that requires numbers to be within a specific range, inclusive.

      Type Parameters

      • T extends number = number

      Parameters

      • min: NoInfer<T>
      • max: NoInfer<T>

      Returns ShapeNumericRange<T>

      import {numericRange, defineShape} from 'object-shape-tester';

      const myShape = defineShape({
      // This will simply produce a type of `number` but will validate runtime values against the range.
      a: numericRange(1, 10),
      });
      // `myShape.runtimeType` is just `{a: number}`

      const myShape2 = defineShape({
      // If you want type safety, you must specify the allowed numbers manually
      a: numericRange<1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10>(1, 10),
      });
      // `myShape2.runtimeType` is `{a: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}`