<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.
export function 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>
>
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.
all<function (type parameter) Brands in 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>>Brands extends readonly [interface Constructor<in out B extends Brand<any>>A constructor for a branded type that provides validation and safe
construction methods.
When to use
Use as the shared callable interface for branded values when an API accepts
or returns a brand constructor and callers need throwing, Option, Result,
or type-guard validation forms.
Constructor<any>, ...interface Array<T>Array<interface Constructor<in out B extends Brand<any>>A constructor for a branded type that provides validation and safe
construction methods.
When to use
Use as the shared callable interface for branded values when an API accepts
or returns a brand constructor and callers need throwing, Option, Result,
or type-guard validation forms.
Constructor<any>>]>(
...brands: Brand.EnsureCommonBase<Brands>(parameter) brands: {
0: Constructor<any>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<Constructor<any>>>): Array<Constructor<any>>; (...items: Array<Constructor<any> | ConcatArray<Constructor<any>>>): Array<Constructor<any>> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<Constructor<any>>;
indexOf: (searchElement: Constructor<any>, fromIndex?: number) => number;
lastIndexOf: (searchElement: Constructor<any>, fromIndex?: number) => number;
every: { (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>…;
some: (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => unknown…;
reduce: { (callbackfn: (previousValue: Constructor<any>, currentValue: Constructor<any>, currentIndex: number, array: ReadonlyArray<Constructor<any>>) => Constructor<any>): Constructor<any>; (callbackfn: (previousValue: Constructor<any>, currentVa…;
reduceRight: { (callbackfn: (previousValue: Constructor<any>, currentValue: Constructor<any>, currentIndex: number, array: ReadonlyArray<Constructor<any>>) => Constructor<any>): Constructor<any>; (callbackfn: (previousValue: Constructor<any>, currentVa…;
find: { (predicate: (value: Constructor<any>, index: number, obj: ReadonlyArray<Constructor<any>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Constructor<any>, index: number, obj: ReadonlyArray<Constructor<any>>) => unknow…;
findIndex: (predicate: (value: Constructor<any>, index: number, obj: ReadonlyArray<Constructor<any>>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, Constructor<any>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Constructor<any>>;
includes: (searchElement: Constructor<any>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Constructor<any>, index: number, array: Array<Constructor<any>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Constructor<any> | undefined;
findLast: { (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => un…;
findLastIndex: (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Constructor<any>>;
toSorted: (compareFn?: ((a: Constructor<any>, b: Constructor<any>) => number) | undefined) => Array<Constructor<any>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Constructor<any>>): Array<Constructor<any>>; (start: number, deleteCount?: number): Array<Constructor<any>> };
with: (index: number, value: Constructor<any>) => Array<Constructor<any>>;
}
brands: Brand.type Brand<in out Keys extends string>.EnsureCommonBase<Brands extends readonly [Constructor<any>, ...Array<Constructor<any>>]> = { [B in keyof Brands]: Brand.Unbranded<Brand.FromConstructor<Brands[0]>> extends Brand.Unbranded<Brand.FromConstructor<Brands[B]>> ? Brand.Unbranded<Brand.FromConstructor<Brands[B]>> extends Brand.Unbranded<Brand.FromConstructor<Brands[0]>> ? Brands[B] : Brands[B] : "ERROR: All brands should have the same base type"; }A utility type that checks that all brands have the same base type.
EnsureCommonBase<function (type parameter) Brands in 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>>Brands>
): interface Constructor<in out B extends Brand<any>>A constructor for a branded type that provides validation and safe
construction methods.
When to use
Use as the shared callable interface for branded values when an API accepts
or returns a brand constructor and callers need throwing, Option, Result,
or type-guard validation forms.
Constructor<
import TypesTypes.type UnionToIntersection<T> = (
T extends any ? (x: T) => any : never
) extends (x: infer R) => any
? R
: never
Transforms a union type into an intersection type.
When to use
Use to combine all members of a union into a single type with all their
properties. This is useful in advanced generic code where you need to merge
union variants.
Details
- Uses distributive conditional types and contra-variant inference.
- If the union members are incompatible (e.g.
string | number), the
result is never.
Example (Converting a union to an intersection)
import type { Types } from "effect"
type Union = { a: string } | { b: number }
type Result = Types.UnionToIntersection<Union>
// { a: string } & { b: number }
UnionToIntersection<{ [function (type parameter) BB in keyof function (type parameter) Brands in 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>>Brands]: Brand.type Brand<in out Keys extends string>.FromConstructor<C> = C extends Constructor<infer B extends Brand<any>> ? B : neverA utility type to extract a branded type from a Constructor.
FromConstructor<function (type parameter) Brands in 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>>Brands[function (type parameter) BB]> }[number]> extends
infer function (type parameter) XX extends interface Brand<in out Keys extends string>A generic interface that defines a branded type.
When to use
Use to define a branded type such as number & Brand<"Positive"> when
TypeScript should keep structurally identical values separate without
changing their runtime value.
Namespace containing type-level helpers for working with branded types and
brand constructors.
Brand<any> ? function (type parameter) XX : interface Brand<in out Keys extends string>A generic interface that defines a branded type.
When to use
Use to define a branded type such as number & Brand<"Positive"> when
TypeScript should keep structurally identical values separate without
changing their runtime value.
Namespace containing type-level helpers for working with branded types and
brand constructors.
Brand<any>
> {
const const checks: Array<SchemaAST.Check<any>>checks = brands: Brand.EnsureCommonBase<Brands>(parameter) brands: {
0: Constructor<any>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<Constructor<any>>>): Array<Constructor<any>>; (...items: Array<Constructor<any> | ConcatArray<Constructor<any>>>): Array<Constructor<any>> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<Constructor<any>>;
indexOf: (searchElement: Constructor<any>, fromIndex?: number) => number;
lastIndexOf: (searchElement: Constructor<any>, fromIndex?: number) => number;
every: { (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>…;
some: (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => unknown…;
reduce: { (callbackfn: (previousValue: Constructor<any>, currentValue: Constructor<any>, currentIndex: number, array: ReadonlyArray<Constructor<any>>) => Constructor<any>): Constructor<any>; (callbackfn: (previousValue: Constructor<any>, currentVa…;
reduceRight: { (callbackfn: (previousValue: Constructor<any>, currentValue: Constructor<any>, currentIndex: number, array: ReadonlyArray<Constructor<any>>) => Constructor<any>): Constructor<any>; (callbackfn: (previousValue: Constructor<any>, currentVa…;
find: { (predicate: (value: Constructor<any>, index: number, obj: ReadonlyArray<Constructor<any>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Constructor<any>, index: number, obj: ReadonlyArray<Constructor<any>>) => unknow…;
findIndex: (predicate: (value: Constructor<any>, index: number, obj: ReadonlyArray<Constructor<any>>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, Constructor<any>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Constructor<any>>;
includes: (searchElement: Constructor<any>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Constructor<any>, index: number, array: Array<Constructor<any>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Constructor<any> | undefined;
findLast: { (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => un…;
findLastIndex: (predicate: (value: Constructor<any>, index: number, array: ReadonlyArray<Constructor<any>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Constructor<any>>;
toSorted: (compareFn?: ((a: Constructor<any>, b: Constructor<any>) => number) | undefined) => Array<Constructor<any>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Constructor<any>>): Array<Constructor<any>>; (start: number, deleteCount?: number): Array<Constructor<any>> };
with: (index: number, value: Constructor<any>) => Array<Constructor<any>>;
}
brands.ReadonlyArray<Constructor<any>>.flatMap<SchemaAST.Check<any>, undefined>(callback: (this: undefined, value: Constructor<any>, index: number, array: Constructor<any>[]) => SchemaAST.Check<any> | readonly SchemaAST.Check<any>[], thisArg?: undefined): SchemaAST.Check<any>[]Calls a defined callback function on each element of an array. Then, flattens the result into
a new array.
This is identical to a map followed by flat with depth 1.
flatMap((brand: Constructor<any>brand) => brand: Constructor<any>brand.Constructor<any>.checks?: readonly [SchemaAST.Check<Brand.Unbranded<B>>, ...Array<SchemaAST.Check<Brand.Unbranded<B>>>] | undefinedThe checks that are applied to the branded type.
checks ?? [])
return import ArrArr.isArrayNonEmpty(const checks: Array<SchemaAST.Check<any>>checks) ?
function check<A extends Brand<any>>(
checks_0: SchemaAST.Check<Brand.Unbranded<A>>,
...checks: Array<
SchemaAST.Check<Brand.Unbranded<A>>
>
): Constructor<A>
Creates a branded type Constructor from one or more schema checks.
When to use
Use when you need a branded type constructor that performs runtime validation
via schema checks.
Details
Calling the returned constructor validates the unbranded value and throws on
failure. Use the returned option, result, or is methods for
non-throwing validation.
check(...const checks: SchemaAST.Check<any>[]const checks: {
0: SchemaAST.Check<any>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => SchemaAST.Check<any> | undefined;
push: (...items: Array<SchemaAST.Check<any>>) => number;
concat: { (...items: Array<ConcatArray<SchemaAST.Check<any>>>): Array<SchemaAST.Check<any>>; (...items: Array<SchemaAST.Check<any> | ConcatArray<SchemaAST.Check<any>>>): Array<SchemaAST.Check<any>> };
join: (separator?: string) => string;
reverse: () => Array<SchemaAST.Check<any>>;
shift: () => SchemaAST.Check<any> | undefined;
slice: (start?: number, end?: number) => Array<SchemaAST.Check<any>>;
sort: (compareFn?: ((a: SchemaAST.Check<any>, b: SchemaAST.Check<any>) => number) | undefined) => [SchemaAST.Check<any>, ...SchemaAST.Check<any>[]];
splice: { (start: number, deleteCount?: number): Array<SchemaAST.Check<any>>; (start: number, deleteCount: number, ...items: Array<SchemaAST.Check<any>>): Array<SchemaAST.Check<any>> };
unshift: (...items: Array<SchemaAST.Check<any>>) => number;
indexOf: (searchElement: SchemaAST.Check<any>, fromIndex?: number) => number;
lastIndexOf: (searchElement: SchemaAST.Check<any>, fromIndex?: number) => number;
every: { (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => value is S, thisArg?: any): this is S[]; (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => unkn…;
some: (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => unknown…;
reduce: { (callbackfn: (previousValue: SchemaAST.Check<any>, currentValue: SchemaAST.Check<any>, currentIndex: number, array: Array<SchemaAST.Check<any>>) => SchemaAST.Check<any>): SchemaAST.Check<any>; (callbackfn: (previousValue: SchemaAST.Check…;
reduceRight: { (callbackfn: (previousValue: SchemaAST.Check<any>, currentValue: SchemaAST.Check<any>, currentIndex: number, array: Array<SchemaAST.Check<any>>) => SchemaAST.Check<any>): SchemaAST.Check<any>; (callbackfn: (previousValue: SchemaAST.Check…;
find: { (predicate: (value: SchemaAST.Check<any>, index: number, obj: Array<SchemaAST.Check<any>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaAST.Check<any>, index: number, obj: Array<SchemaAST.Check<any>>) => unknow…;
findIndex: (predicate: (value: SchemaAST.Check<any>, index: number, obj: Array<SchemaAST.Check<any>>) => unknown, thisArg?: any) => number;
fill: (value: SchemaAST.Check<any>, start?: number, end?: number) => [SchemaAST.Check<any>, ...SchemaAST.Check<any>[]];
copyWithin: (target: number, start: number, end?: number) => [SchemaAST.Check<any>, ...SchemaAST.Check<any>[]];
entries: () => ArrayIterator<[number, SchemaAST.Check<any>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<SchemaAST.Check<any>>;
includes: (searchElement: SchemaAST.Check<any>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => SchemaAST.Check<any> | undefined;
findLast: { (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => un…;
findLastIndex: (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<SchemaAST.Check<any>>;
toSorted: (compareFn?: ((a: SchemaAST.Check<any>, b: SchemaAST.Check<any>) => number) | undefined) => Array<SchemaAST.Check<any>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<SchemaAST.Check<any>>): Array<SchemaAST.Check<any>>; (start: number, deleteCount?: number): Array<SchemaAST.Check<any>> };
with: (index: number, value: SchemaAST.Check<any>) => Array<SchemaAST.Check<any>>;
}
checks) :
function nominal<
A extends Brand<any>
>(): Constructor<A>
Returns a Constructor that does not apply any runtime checks and just
returns the provided value.
When to use
Use to create nominal types that allow distinguishing between two values
of the same type but with different meanings.
nominal()
}