effect-io-ai

Package: effect
Module: Data

Data.TaggedEnum.Args

Extracts the constructor argument type for a specific variant of a tagged union.

When to use

Use to derive the argument object expected by a constructor for one tagged union variant.

Details

Returns void if the variant has no fields beyond _tag.

Example (Extracting variant args)

import type { Data } from "effect"

type Result =
  | { readonly _tag: "Ok"; readonly value: number }
  | { readonly _tag: "Err"; readonly error: string }

type OkArgs = Data.TaggedEnum.Args<Result, "Ok">
// { readonly value: number }

type ErrArgs = Data.TaggedEnum.Args<Result, "Err">
// { readonly error: string }

See

Signature

type Args<A, K, E> = {
    readonly [K in keyof E as K extends "_tag" ? never : K]: E[K]
  } extends infer T ? Types.VoidIfEmpty<T>
    : never

Source

Since v2.0.0