<N extends Newtype.Any>(newtype: N): Newtype.Carrier<N>Unwraps a newtype value, returning the underlying carrier value.
When to use
Use when you need the carrier value from an existing newtype without constructing a new newtype value at the same call site.
Details
This has zero runtime cost because it is an identity cast.
Example (Unwrapping a newtype)
import { Newtype } from "effect"
interface Label extends Newtype.Newtype<"Label", string> {}
const iso = Newtype.makeIso<Label>()
const label = iso.set("hello")
const raw: string = Newtype.value(label) // "hello"export const const value: <N extends Newtype.Any>(
newtype: N
) => Newtype.Carrier<N>
Unwraps a newtype value, returning the underlying carrier value.
When to use
Use when you need the carrier value from an existing newtype without
constructing a new newtype value at the same call site.
Details
This has zero runtime cost because it is an identity cast.
Example (Unwrapping a newtype)
import { Newtype } from "effect"
interface Label extends Newtype.Newtype<"Label", string> {}
const iso = Newtype.makeIso<Label>()
const label = iso.set("hello")
const raw: string = Newtype.value(label) // "hello"
value: <function (type parameter) N in <N extends Newtype.Any>(newtype: N): Newtype.Carrier<N>N extends Newtype.type Newtype<in out Key extends string, out Carrier>.Any = Newtype<any, unknown>A type that matches any Newtype, useful as a generic constraint:
<N extends Newtype.Any>.
When to use
Use as a generic constraint when a type parameter can be any Newtype.
Any>(newtype: N extends Newtype.Anynewtype: function (type parameter) N in <N extends Newtype.Any>(newtype: N): Newtype.Carrier<N>N) => Newtype.type Newtype<in out Key extends string, out Carrier>.Carrier<N extends Newtype.Any> = N extends Newtype<infer _Key extends string, infer Carrier> ? Carrier : neverExtracts the carrier (underlying) type from a newtype.
When to use
Use when you need to refer to the wrapped type in generic utilities.
Carrier<function (type parameter) N in <N extends Newtype.Any>(newtype: N): Newtype.Carrier<N>N> = import castcast