<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.type Brand.Brand = /*unresolved*/ anyBrand<any>>(identifier: stringidentifier: string, ctor: Brand.Constructor<A>ctor: import BrandBrand.type Brand.Constructor = /*unresolved*/ anyConstructor<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.declareBrand.type Brand.Brand.Unbranded = /*unresolved*/ anyUnbranded<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.declareBrand.type Brand.Brand.Keys = /*unresolved*/ anyKeys<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.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.checks) : self: S extends Top & { readonly "Type": Brand.Brand.Unbranded<A>; }self).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))
}
}