ts-fortress
    Preparing search index...

    Function refine

    • Narrows a primitive type by a predicate.

      The constraint values the base type carries (see WithConstraints) are carried over to the refined type, so that t.refine({ baseType: t.number(0, { min: 0, max: 10 }), ... }).constraints still reads min and max. C is inferred from baseType.constraints; refining a base type that carries none adds no constraints property.

      Type Parameters

      • Base extends StrictExtract<Primitive, string | number | bigint | boolean>
      • R extends StrictExtract<Primitive, string | number | bigint | boolean>
      • const C = unknown

      Parameters

      • __namedParameters: Readonly<
            {
                baseType: Type<Base> & Partial<WithConstraints<C>>;
                defaultValue: R;
                getConstraintDetails?: (a: Base) => ValidationErrorDetails | undefined;
                is: (a: Base) => a is R;
                typeName?: string;
            },
        >

      Returns Readonly<
          {
              assertIs: (a: unknown) => asserts a is R;
              cast: (a: unknown) => R;
              defaultValue: R;
              fill: (a: unknown) => R;
              is: (a: unknown) => a is R;
              prune: <
                  B extends StrictExtract<Primitive, string | number | bigint | boolean>,
              >(
                  a: B,
              ) => R;
              typeName: string;
              validate: (
                  a: unknown,
              ) => Result<
                  R,
                  readonly Readonly<
                      {
                          actualValue: unknown;
                          details?: ValidationErrorDetails;
                          expectedType: string;
                          path: readonly string[];
                          typeName: string;
                      },
                  >[],
              >;
          },
      > & ConstraintsCarrier<C>