<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.
export function 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<function (type parameter) A in nominal<A extends Brand<any>>(): Constructor<A>A 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>>(): 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<function (type parameter) A in nominal<A extends Brand<any>>(): Constructor<A>A> {
return var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.assign<(input: Brand.Unbranded<A>) => A, {
option: (input: Brand.Unbranded<A>) => Option.Option<A>;
result: (input: Brand.Unbranded<A>) => Result.Result<A, never>;
is: (_: Brand.Unbranded<A>) => _ is Brand.Unbranded<A> & A;
}>(target: (input: Brand.Unbranded<A>) => A, source: {
option: (input: Brand.Unbranded<A>) => Option.Option<A>;
result: (input: Brand.Unbranded<A>) => Result.Result<A, never>;
is: (_: Brand.Unbranded<A>) => _ is Brand.Unbranded<A> & A;
}): ((input: Brand.Unbranded<A>) => A) & {
option: (input: Brand.Unbranded<A>) => Option.Option<A>;
result: (input: Brand.Unbranded<A>) => Result.Result<A, never>;
is: (_: Brand.Unbranded<A>) => _ is Brand.Unbranded<A> & A;
} (+3 overloads)
Copy the values of all of the enumerable own properties from one or more source objects to a
target object. Returns the target object.
assign((input: Brand.Unbranded<A>input: 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) A in nominal<A extends Brand<any>>(): Constructor<A>A>) => input: Brand.Unbranded<A>input as function (type parameter) A in nominal<A extends Brand<any>>(): Constructor<A>A, {
option: (
input: Brand.Unbranded<A>
) => Option.Option<A>
option: (input: Brand.Unbranded<A>input: 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) A in nominal<A extends Brand<any>>(): Constructor<A>A>) => import OptionOption.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(input: Brand.Unbranded<A>input as function (type parameter) A in nominal<A extends Brand<any>>(): Constructor<A>A),
result: (
input: Brand.Unbranded<A>
) => Result.Result<A, never>
result: (input: Brand.Unbranded<A>input: 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) A in nominal<A extends Brand<any>>(): Constructor<A>A>) => import ResultResult.const succeed: <A>(right: A) => Result<A>Creates a Result holding a Success value.
Details
- Use when you have a value and want to lift it into the
Result type
- The error type
E defaults to never
Example (Wrapping a value)
import { Result } from "effect"
const result = Result.succeed(42)
console.log(Result.isSuccess(result))
// Output: true
succeed(input: Brand.Unbranded<A>input as function (type parameter) A in nominal<A extends Brand<any>>(): Constructor<A>A),
is: (
_: Brand.Unbranded<A>
) => _ is Brand.Unbranded<A> & A
is: (_: Brand.Unbranded<A>_: 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) A in nominal<A extends Brand<any>>(): Constructor<A>A>): _: Brand.Unbranded<A>_ 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) A in nominal<A extends Brand<any>>(): Constructor<A>A> & function (type parameter) A in nominal<A extends Brand<any>>(): Constructor<A>A => true
})
}