<A extends Brand.Brand<any>>(
identifier: string,
ctor: Brand.Constructor<A>
): <S extends Top & { readonly Type: Brand.Brand.Unbranded<A> }>(
self: S
) => brand<S["Rebuild"], Brand.Brand.Keys<A>>Creates a branded schema from a Brand.Constructor, applying the constructor's checks and brand tag to the underlying schema.
export function function fromBrand<
A extends Brand.Brand<any>
>(
identifier: string,
ctor: Brand.Constructor<A>
): <
S extends Top & {
readonly Type: Brand.Brand.Unbranded<A>
}
>(
self: S
) => brand<S["Rebuild"], Brand.Brand.Keys<A>>
Creates a branded schema from a
Brand.Constructor
, applying the
constructor's checks and brand tag to the underlying schema.
fromBrand<function (type parameter) A in fromBrand<A extends Brand.Brand<any>>(identifier: string, ctor: Brand.Constructor<A>): <S extends Top & {
readonly "Type": Brand.Brand.Unbranded<A>;
}>(self: S) => brand<S["Rebuild"], Brand.Brand.Keys<A>>
A extends import BrandBrand.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>>(identifier: stringidentifier: string, ctor: Brand.Constructor<A>ctor: import BrandBrand.interface Constructor<in out B extends Brand.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<function (type parameter) A in fromBrand<A extends Brand.Brand<any>>(identifier: string, ctor: Brand.Constructor<A>): <S extends Top & {
readonly "Type": Brand.Brand.Unbranded<A>;
}>(self: S) => brand<S["Rebuild"], Brand.Brand.Keys<A>>
A>) {
return <function (type parameter) S in <S extends Top & {
readonly "Type": Brand.Brand.Unbranded<A>;
}>(self: S): brand<S["Rebuild"], Brand.Brand.Keys<A>>
S extends Top & { readonly "Type": import BrandBrand.Brand.type Brand<in out Keys extends string>.Unbranded<B extends Brand.Brand<any>> = B extends infer U & UnionToIntersection<{ [K in keyof B["~effect/Brand"]]: K extends string ? Brand.Brand<K> : never; }[keyof B["~effect/Brand"]]> ? U : BA utility type to extract the unbranded value type from a brand.
Unbranded<function (type parameter) A in fromBrand<A extends Brand.Brand<any>>(identifier: string, ctor: Brand.Constructor<A>): <S extends Top & {
readonly "Type": Brand.Brand.Unbranded<A>;
}>(self: S) => brand<S["Rebuild"], Brand.Brand.Keys<A>>
A> }>(
self: S extends Top & { readonly "Type": Brand.Brand.Unbranded<A>; }self: function (type parameter) S in <S extends Top & {
readonly "Type": Brand.Brand.Unbranded<A>;
}>(self: S): brand<S["Rebuild"], Brand.Brand.Keys<A>>
S
): interface brand<S extends Constraint, B>Adds a nominal brand to a schema, intersecting the output type with
Brand.Brand<B> to prevent accidental mixing of structurally identical types.
When to use
Use to make values decoded by an existing schema nominally distinct when the
schema already carries the runtime validation you need.
Gotchas
brand adds brand metadata and narrows the TypeScript output type, but it
does not add runtime checks.
Type-level representation returned by
brand
.
brand<function (type parameter) S in <S extends Top & {
readonly "Type": Brand.Brand.Unbranded<A>;
}>(self: S): brand<S["Rebuild"], Brand.Brand.Keys<A>>
S["Rebuild"], import BrandBrand.Brand.type Brand<in out Keys extends string>.Keys<B extends Brand.Brand<any>> = keyof B["~effect/Brand"]A utility type to extract the keys of a branded type.
Keys<function (type parameter) A in fromBrand<A extends Brand.Brand<any>>(identifier: string, ctor: Brand.Constructor<A>): <S extends Top & {
readonly "Type": Brand.Brand.Unbranded<A>;
}>(self: S) => brand<S["Rebuild"], Brand.Brand.Keys<A>>
A>> => {
return (ctor: Brand.Constructor<A>ctor.Constructor<A>.checks?: readonly [SchemaAST.Check<Brand.Unbranded<B>>, ...Array<SchemaAST.Check<Brand.Unbranded<B>>>] | undefinedThe checks that are applied to the branded type.
checks ? self: S extends Top & { readonly "Type": Brand.Brand.Unbranded<A>; }self.Bottom<unknown, unknown, unknown, unknown, AST, Top, unknown, unknown, any, unknown, Mutability, Optionality, ConstructorDefault, Mutability, Optionality>.check(checks_0: SchemaAST.Check<S["Type"]>, ...checks: SchemaAST.Check<S["Type"]>[]): S["Rebuild"]check(...ctor: Brand.Constructor<A>ctor.Constructor<A>.checks?: readonly [SchemaAST.Check<Brand.Unbranded<B>>, ...Array<SchemaAST.Check<Brand.Unbranded<B>>>] | undefined(property) Constructor<A>.checks?: {
0: SchemaAST.Check<Brand.Brand.Unbranded<A>>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>>): Array<SchemaAST.Check<Brand.Brand.Unbranded<A>>>; (...items: Array<SchemaAST.Check<Brand.Brand.Unbranded<A>> | ConcatArray<SchemaAST.Check<Brand.Brand.Unbranded<A…;
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<SchemaAST.Check<Brand.Brand.Unbranded<A>>>;
indexOf: (searchElement: SchemaAST.Check<Brand.Brand.Unbranded<A>>, fromIndex?: number) => number;
lastIndexOf: (searchElement: SchemaAST.Check<Brand.Brand.Unbranded<A>>, fromIndex?: number) => number;
every: { (predicate: (value: SchemaAST.Check<Brand.Brand.Unbranded<A>>, index: number, array: ReadonlyArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: SchemaAST.Check<Brand…;
some: (predicate: (value: SchemaAST.Check<Brand.Brand.Unbranded<A>>, index: number, array: ReadonlyArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: SchemaAST.Check<Brand.Brand.Unbranded<A>>, index: number, array: ReadonlyArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: SchemaAST.Check<Brand.Brand.Unbranded<A>>, index: number, array: ReadonlyArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: SchemaAST.Check<Brand.Brand.Unbranded<A>>, index: number, array: ReadonlyArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: SchemaAST.Check<Brand.Brand.Unbra…;
reduce: { (callbackfn: (previousValue: SchemaAST.Check<Brand.Brand.Unbranded<A>>, currentValue: SchemaAST.Check<Brand.Brand.Unbranded<A>>, currentIndex: number, array: ReadonlyArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => SchemaAST.Check<Br…;
reduceRight: { (callbackfn: (previousValue: SchemaAST.Check<Brand.Brand.Unbranded<A>>, currentValue: SchemaAST.Check<Brand.Brand.Unbranded<A>>, currentIndex: number, array: ReadonlyArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => SchemaAST.Check<Br…;
find: { (predicate: (value: SchemaAST.Check<Brand.Brand.Unbranded<A>>, index: number, obj: ReadonlyArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaAST.Check<Brand.Brand.Un…;
findIndex: (predicate: (value: SchemaAST.Check<Brand.Brand.Unbranded<A>>, index: number, obj: ReadonlyArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, SchemaAST.Check<Brand.Brand.Unbranded<A>>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<SchemaAST.Check<Brand.Brand.Unbranded<A>>>;
includes: (searchElement: SchemaAST.Check<Brand.Brand.Unbranded<A>>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: SchemaAST.Check<Brand.Brand.Unbranded<A>>, index: number, array: Array<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => SchemaAST.Check<Brand.Brand.Unbranded<A>> | undefined;
findLast: { (predicate: (value: SchemaAST.Check<Brand.Brand.Unbranded<A>>, index: number, array: ReadonlyArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaAST.Check<Brand.Brand.…;
findLastIndex: (predicate: (value: SchemaAST.Check<Brand.Brand.Unbranded<A>>, index: number, array: ReadonlyArray<SchemaAST.Check<Brand.Brand.Unbranded<A>>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<SchemaAST.Check<Brand.Brand.Unbranded<A>>>;
toSorted: (compareFn?: ((a: SchemaAST.Check<Brand.Brand.Unbranded<A>>, b: SchemaAST.Check<Brand.Brand.Unbranded<A>>) => number) | undefined) => Array<SchemaAST.Check<Brand.Brand.Unbranded<A>>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<SchemaAST.Check<Brand.Brand.Unbranded<A>>>): Array<SchemaAST.Check<Brand.Brand.Unbranded<A>>>; (start: number, deleteCount?: number): Array<SchemaAST.Check<Brand.Brand.Unbranded<A>>> };
with: (index: number, value: SchemaAST.Check<Brand.Brand.Unbranded<A>>) => Array<SchemaAST.Check<Brand.Brand.Unbranded<A>>>;
}
The checks that are applied to the branded type.
checks) : self: S extends Top & { readonly "Type": Brand.Brand.Unbranded<A>; }self).Pipeable.pipe<S | S["Rebuild"], brand<(S | S["Rebuild"])["Rebuild"], string>>(this: S | S["Rebuild"], ab: (_: S | S["Rebuild"]) => brand<(S | S["Rebuild"])["Rebuild"], string>): brand<(S | S["Rebuild"])["Rebuild"], string> (+21 overloads)pipe(function brand<B extends string>(
identifier: B
): <S extends ConstraintRebuildable>(
schema: S
) => brand<S["Rebuild"], B>
Adds a nominal brand to a schema, intersecting the output type with
Brand.Brand<B> to prevent accidental mixing of structurally identical types.
When to use
Use to make values decoded by an existing schema nominally distinct when the
schema already carries the runtime validation you need.
Gotchas
brand adds brand metadata and narrows the TypeScript output type, but it
does not add runtime checks.
brand(identifier: stringidentifier))
}
}