<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.PipeableProvides 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"export const 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
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"
TaggedClass = <function (type parameter) Tag in <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
Tag extends string>(
tag: Tag extends stringtag: function (type parameter) Tag in <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
Tag
): new<function (type parameter) A in <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
A extends type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, any> = {}>(
args: Types.VoidIfEmpty<{
readonly [P in keyof A as P extends "_tag"
? never
: P]: A[P]
}>
args: import TypesTypes.type VoidIfEmpty<S> =
keyof S extends never ? void : S
Conditional type that returns void if S is an empty object type,
otherwise returns S.
When to use
Use to erase an empty object type from an API result or parameter position.
VoidIfEmpty<{ readonly [function (type parameter) PP in keyof function (type parameter) A in <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
A as function (type parameter) PP extends "_tag" ? never : function (type parameter) PP]: function (type parameter) A in <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
A[function (type parameter) PP] }>
) => type Readonly<T> = {
readonly [P in keyof T]: T[P]
}
Make all properties in T readonly
Readonly<function (type parameter) A in <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
A> & { readonly _tag: Tag extends string_tag: function (type parameter) Tag in <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
Tag } & import PipeablePipeable.Pipeable =>
class extends const Class: new <
A extends Record<string, any> = {}
>(
args: Types.VoidIfEmpty<{
readonly [P in keyof A]: A[P]
}>
) => Readonly<A> & Pipeable.Pipeable
Provides a base class for immutable data types.
When to use
Use when you need a lightweight immutable value type with .pipe() support.
Details
Extend Class with a type parameter to declare fields. The constructor
accepts those fields as a single object argument. When there are no fields
the argument is optional. Instances are Readonly and Pipeable.
Example (Defining a value class)
import { Data, Equal } from "effect"
class Person extends Data.Class<{ readonly name: string }> {}
const mike1 = new Person({ name: "Mike" })
const mike2 = new Person({ name: "Mike" })
console.log(Equal.equals(mike1, mike2))
// true
Class {
readonly function (Anonymous class)._tag: Tag extends string_tag = tag: Tag extends stringtag
} as any