API reference / @evolu/common / Type / BrandFactory

Type Alias: BrandFactory()<Name, Input, RefineError>

type BrandFactory<Name, Input, RefineError> = <
  PName,
  P,
  PInput,
  PParent,
  PError,
  PParentError,
>(
  parent,
) => BrandType<
  Type<PName, P, PInput, PError, PParent, PParentError>,
  Name,
  RefineError,
  PError | PParentError
>;

Defined in: packages/common/src/Type.ts:1142

Helper type for Type Factory that creates a branded Type.

Example

const trimmed: BrandFactory<"Trimmed", string, TrimmedError> = (parent) =>
  brand("Trimmed", parent, (value) =>
    value.trim().length === value.length
      ? ok(value)
      : err<TrimmedError>({ type: "Trimmed", value }),
  );

Type Parameters

Type Parameter
Name extends TypeName
Input
RefineError extends TypeError

Type Parameters

Type ParameterDefault type
PName extends TypeName-
P extends Input-
PInput-
PParent-
PError extends TypeErrornever
PParentError extends TypeErrornever

Parameters

ParameterType
parentType<PName, P, PInput, PError, PParent, PParentError>

Returns

BrandType<Type<PName, P, PInput, PError, PParent, PParentError>, Name, RefineError, PError | PParentError>

Was this page helpful?