Skip to content

Provide runtime type detection API for Effect data types #5730

@jasonkuhrt

Description

@jasonkuhrt

Currently, there's no standard way to detect Effect data types (Option, Either, etc.) at runtime and retrieve their type names for generic dispatch systems (like trait implementations).

Use case: Building a trait system that needs to:

  1. Detect if a value is an Effect type (vs native JS type)
  2. Get the type name (e.g., "Option", "Either") for dispatch

Current approach:

// Check for TypeId symbol and parse description
for (const typeId of [Option.TypeId, Either.TypeId]) {
  if (typeId in value) {
    const typeName = typeId.description?.slice(7) // "effect/Option" → "Option"
    return typeName
  }
}

Issues:

  • Brittle: relies on Symbol.description format "effect/TypeName"
  • Requires maintaining hardcoded list of TypeId symbols
  • No way to detect all Effect types generically

Proposed solution:

Effect.getTypeName(value) // "Option" | "Either" | ... | null

This single API provides both detection (non-null) and identification (the name), enabling generic handling of Effect types in libraries without brittle Symbol parsing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions