brand<S, 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.
export interface 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 brand<S extends Constraint, B>S extends Constraint, function (type parameter) B in brand<S extends Constraint, B>B> extends
interface BottomLazy<out Ast extends SchemaAST.AST, out Rebuild extends Top, in out TypeParameters extends ReadonlyArray<Constraint> = readonly [], out TypeMutability extends Mutability = "readonly", out TypeOptionality extends Optionality = "required", out TypeConstructorDefault extends ConstructorDefault = "no-default", out EncodedMutability extends Mutability = "readonly", out EncodedOptionality extends Optionality = "required">Lazy Bottom variant for schema implementations that compute their public
views on demand.
When to use
Use as an implementation base for schema interfaces that must expose
Bottom behavior without forcing TypeScript to eagerly evaluate expensive
Type, Encoded, or service views.
Details
The laziness is purely type-level; runtime behavior is unchanged.
BottomLazy keeps the structural operations inherited from Bottom, but
erases the expensive schema views to unknown. Concrete schema interfaces can
then redeclare the precise views they expose. This keeps wide schemas such as
Struct and Union cheaper when generic code reads a single view, while
preserving their exact public types.
BottomLazy<
function (type parameter) S in brand<S extends Constraint, B>S["ast"],
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 brand<S extends Constraint, B>S, function (type parameter) B in brand<S extends Constraint, B>B>,
function (type parameter) S in brand<S extends Constraint, B>S["~type.parameters"],
function (type parameter) S in brand<S extends Constraint, B>S["~type.mutability"],
function (type parameter) S in brand<S extends Constraint, B>S["~type.optionality"],
function (type parameter) S in brand<S extends Constraint, B>S["~type.constructor.default"],
function (type parameter) S in brand<S extends Constraint, B>S["~encoded.mutability"],
function (type parameter) S in brand<S extends Constraint, B>S["~encoded.optionality"]
>
{
readonly "Type": function (type parameter) S in brand<S extends Constraint, B>S["Type"] & type DistributeBrands<B> = (
(
B extends infer U extends string
? Brand.Brand<U>
: never
) extends any
? (
x: B extends infer U extends string
? Brand.Brand<U>
: never
) => any
: never
) extends (x: infer R) => any
? R
: never
DistributeBrands<function (type parameter) B in brand<S extends Constraint, B>B>
readonly "Encoded": function (type parameter) S in brand<S extends Constraint, B>S["Encoded"]
readonly "DecodingServices": function (type parameter) S in brand<S extends Constraint, B>S["DecodingServices"]
readonly "EncodingServices": function (type parameter) S in brand<S extends Constraint, B>S["EncodingServices"]
readonly "~type.make.in": function (type parameter) S in brand<S extends Constraint, B>S["~type.make.in"]
readonly "~type.make": function (type parameter) S in brand<S extends Constraint, B>S["Type"] & type DistributeBrands<B> = (
(
B extends infer U extends string
? Brand.Brand<U>
: never
) extends any
? (
x: B extends infer U extends string
? Brand.Brand<U>
: never
) => any
: never
) extends (x: infer R) => any
? R
: never
DistributeBrands<function (type parameter) B in brand<S extends Constraint, B>B>
readonly "Iso": function (type parameter) S in brand<S extends Constraint, B>S["Type"] & type DistributeBrands<B> = (
(
B extends infer U extends string
? Brand.Brand<U>
: never
) extends any
? (
x: B extends infer U extends string
? Brand.Brand<U>
: never
) => any
: never
) extends (x: infer R) => any
? R
: never
DistributeBrands<function (type parameter) B in brand<S extends Constraint, B>B>
readonly brand<S extends Constraint, B>.schema: S extends Constraintschema: function (type parameter) S in brand<S extends Constraint, B>S
readonly brand<S extends Constraint, B>.identifier: stringidentifier: string
}
/**
* 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.
*
* @see {@link fromBrand} for applying a Brand constructor's checks along with the brand tag
*
* @category branding
* @since 3.10.0
*/
export function 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<function (type parameter) B in brand<B extends string>(identifier: B): <S extends ConstraintRebuildable>(schema: S) => brand<S["Rebuild"], B>B extends string>(identifier: B extends stringidentifier: function (type parameter) B in brand<B extends string>(identifier: B): <S extends ConstraintRebuildable>(schema: S) => brand<S["Rebuild"], B>B) {
return <function (type parameter) S in <S extends ConstraintRebuildable>(schema: S): brand<S["Rebuild"], B>S extends ConstraintRebuildable>(schema: S extends ConstraintRebuildableschema: function (type parameter) S in <S extends ConstraintRebuildable>(schema: S): brand<S["Rebuild"], B>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 ConstraintRebuildable>(schema: S): brand<S["Rebuild"], B>S["Rebuild"], function (type parameter) B in brand<B extends string>(identifier: B): <S extends ConstraintRebuildable>(schema: S) => brand<S["Rebuild"], B>B> =>
const make: <S extends Constraint>(
ast: S["ast"],
options?: object
) => S
Creates a schema from an AST (Abstract Syntax Tree) node.
Details
This is the fundamental constructor for all schemas in the Effect Schema
library. It takes an AST node and wraps it in a fully-typed schema that
preserves all type information and provides the complete schema API.
The make function is used internally to create all primitive schemas like
String, Number, Boolean, etc., as well as more complex schemas. It's
the bridge between the untyped AST representation and the strongly-typed
schema.
make(import SchemaASTSchemaAST.function brand(
ast: AST,
brand: string
): AST
brand(schema: S extends ConstraintRebuildableschema.Constraint["ast"]: SchemaAST.ASTast, identifier: B extends stringidentifier), { schema: S extends ConstraintRebuildableschema, identifier: B extends stringidentifier })
}