Package: effect
Module: Data
Provides a base class for immutable data types with a _tag discriminator.
When to use
Use when you need a single-variant tagged type or an ad-hoc discriminator.
Details
Like Class, but the resulting instances also carry a
readonly _tag: Tag property. The _tag is excluded from the constructor
argument.
Example (Defining a tagged class)
import { Data } from "effect"
class Person extends Data.TaggedClass("Person")<{
readonly name: string
}> {}
const mike = new Person({ name: "Mike" })
console.log(mike._tag)
// "Person"
See
Class — without a _tagTaggedError — tagged error variantTaggedEnum — multi-variant unionsSignature
declare const TaggedClass: <Tag extends string>(tag: Tag) => new <A extends Record<string, any> = {}>(args: Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & { readonly _tag: Tag; } & Pipeable.Pipeable
Since v2.0.0