effect-io-ai

Package: effect
Module: Data

Data.TaggedClass

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

Signature

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

Source

Since v2.0.0