Hyperlinkv0.8.0-beta.28

Brand

Brand.allfunctioneffect/Brand.ts:308
<Brands extends readonly [Constructor<any>, ...Array<Constructor<any>>]>(
  ...brands: Brand.EnsureCommonBase<Brands>
): Constructor<
  Types.UnionToIntersection<
    { [B in keyof Brands]: Brand.FromConstructor<Brands[B]> }[number]
  > extends infer X extends Brand<any>
    ? X
    : Brand<any>
>

Combines one or more brand constructors to form a single branded type.

When to use

Use to require an input to satisfy every runtime check collected by the provided brand constructors.

Details

If the provided constructors contain runtime checks, the combined constructor succeeds only when all checks pass. If no runtime checks are present, it behaves as a nominal constructor.

combining
Source effect/Brand.ts:30811 lines
export function all<Brands extends readonly [Constructor<any>, ...Array<Constructor<any>>]>(
  ...brands: Brand.EnsureCommonBase<Brands>
): Constructor<
  Types.UnionToIntersection<{ [B in keyof Brands]: Brand.FromConstructor<Brands[B]> }[number]> extends
    infer X extends Brand<any> ? X : Brand<any>
> {
  const checks = brands.flatMap((brand) => brand.checks ?? [])
  return Arr.isArrayNonEmpty(checks) ?
    check(...checks) :
    nominal()
}