(unbranded: Brand.Unbranded<B>): BA 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.
export interface 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<in out function (type parameter) B in Constructor<in out B extends Brand<any>>B 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>> {
/**
* Constructs a branded type from a value of type `Unbranded<B>`, throwing an
* error if the provided value is not valid.
*/
(unbranded: Brand.Unbranded<B>unbranded: Brand.type Brand<in out Keys extends string>.Unbranded<B extends Brand<any>> = B extends infer U & Types.UnionToIntersection<{ [K in keyof B["~effect/Brand"]]: K extends string ? Brand<K> : never; }[keyof B["~effect/Brand"]]> ? U : BA utility type to extract the unbranded value type from a brand.
Unbranded<function (type parameter) B in Constructor<in out B extends Brand<any>>B>): function (type parameter) B in Constructor<in out B extends Brand<any>>B
/**
* Constructs a branded type from a value of type `Unbranded<B>`, returning
* `Some<B>` if the provided value is valid, `None` otherwise.
*/
function Constructor(unbranded: Brand.Unbranded<B>): Option.Option<B>Constructs a branded type from a value of type Unbranded<B>, returning
Some<B> if the provided value is valid, None otherwise.
option(unbranded: Brand.Unbranded<B>unbranded: Brand.type Brand<in out Keys extends string>.Unbranded<B extends Brand<any>> = B extends infer U & Types.UnionToIntersection<{ [K in keyof B["~effect/Brand"]]: K extends string ? Brand<K> : never; }[keyof B["~effect/Brand"]]> ? U : BA utility type to extract the unbranded value type from a brand.
Unbranded<function (type parameter) B in Constructor<in out B extends Brand<any>>B>): import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) B in Constructor<in out B extends Brand<any>>B>
/**
* Constructs a branded type from a value of type `Unbranded<B>`, returning
* `Success<B>` if the provided value is valid, `Failure<BrandError>`
* otherwise.
*/
function Constructor(unbranded: Brand.Unbranded<B>): Result.Result<B, BrandError>Constructs a branded type from a value of type Unbranded<B>, returning
Success<B> if the provided value is valid, Failure<BrandError>
otherwise.
result(unbranded: Brand.Unbranded<B>unbranded: Brand.type Brand<in out Keys extends string>.Unbranded<B extends Brand<any>> = B extends infer U & Types.UnionToIntersection<{ [K in keyof B["~effect/Brand"]]: K extends string ? Brand<K> : never; }[keyof B["~effect/Brand"]]> ? U : BA utility type to extract the unbranded value type from a brand.
Unbranded<function (type parameter) B in Constructor<in out B extends Brand<any>>B>): import ResultResult.type Result<A, E = never> = Result.Success<A, E> | Result.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<function (type parameter) B in Constructor<in out B extends Brand<any>>B, class BrandErrorclass BrandError {
_tag: 'BrandError';
name: string;
issue: SchemaIssue.Issue;
message: string;
toString: () => string;
}
Error returned when a branded type is constructed from an invalid value.
Details
The error wraps a SchemaIssue.Issue, exposes message through
issue.toString(), and formats as BrandError(<message>).
Gotchas
BrandError is an error-like model with _tag, name, message, and
toString; it does not extend JavaScript Error.
BrandError>
/**
* Attempts to refine the provided value of type `Unbranded<B>`, returning
* `true` if the provided value is a valid branded type, `false` otherwise.
*/
Constructor<in out B extends Brand<any>>.is(unbranded: Brand.Unbranded<B>): unbranded is Brand.Unbranded<B> & BAttempts to refine the provided value of type Unbranded<B>, returning
true if the provided value is a valid branded type, false otherwise.
is(unbranded: Brand.Unbranded<B>unbranded: Brand.type Brand<in out Keys extends string>.Unbranded<B extends Brand<any>> = B extends infer U & Types.UnionToIntersection<{ [K in keyof B["~effect/Brand"]]: K extends string ? Brand<K> : never; }[keyof B["~effect/Brand"]]> ? U : BA utility type to extract the unbranded value type from a brand.
Unbranded<function (type parameter) B in Constructor<in out B extends Brand<any>>B>): unbranded: Brand.Unbranded<B>unbranded is Brand.type Brand<in out Keys extends string>.Unbranded<B extends Brand<any>> = B extends infer U & Types.UnionToIntersection<{ [K in keyof B["~effect/Brand"]]: K extends string ? Brand<K> : never; }[keyof B["~effect/Brand"]]> ? U : BA utility type to extract the unbranded value type from a brand.
Unbranded<function (type parameter) B in Constructor<in out B extends Brand<any>>B> & function (type parameter) B in Constructor<in out B extends Brand<any>>B
/**
* The checks that are applied to the branded type.
*
* @internal
*/
Constructor<in out B extends Brand<any>>.checks?: readonly [SchemaAST.Check<Brand.Unbranded<B>>, ...Array<SchemaAST.Check<Brand.Unbranded<B>>>] | undefinedThe checks that are applied to the branded type.
checks?: readonly [import SchemaASTSchemaAST.type Check<T> =
| SchemaAST.Filter<T>
| SchemaAST.FilterGroup<T>
Check<Brand.type Brand<in out Keys extends string>.Unbranded<B extends Brand<any>> = B extends infer U & Types.UnionToIntersection<{ [K in keyof B["~effect/Brand"]]: K extends string ? Brand<K> : never; }[keyof B["~effect/Brand"]]> ? U : BA utility type to extract the unbranded value type from a brand.
Unbranded<function (type parameter) B in Constructor<in out B extends Brand<any>>B>>, ...interface Array<T>Array<import SchemaASTSchemaAST.type Check<T> =
| SchemaAST.Filter<T>
| SchemaAST.FilterGroup<T>
Check<Brand.type Brand<in out Keys extends string>.Unbranded<B extends Brand<any>> = B extends infer U & Types.UnionToIntersection<{ [K in keyof B["~effect/Brand"]]: K extends string ? Brand<K> : never; }[keyof B["~effect/Brand"]]> ? U : BA utility type to extract the unbranded value type from a brand.
Unbranded<function (type parameter) B in Constructor<in out B extends Brand<any>>B>>>] | undefined
}