Hyperlinkv0.8.0-beta.28

Inspectable

Inspectable.NodeInspectSymboltypeeffect/Inspectable.ts:49
typeof NodeInspectSymbol

Defines the symbol used by Node.js for custom object inspection.

When to use

Use to implement Node.js custom inspection for a value.

Details

This symbol is recognized by Node.js's util.inspect() function and the REPL for custom object representation. When an object has a method with this symbol, it will be called to determine how the object should be displayed.

Example (Defining custom Node inspection)

import { Inspectable } from "effect"

class CustomObject {
  constructor(private value: string) {}

  [Inspectable.NodeInspectSymbol]() {
    return `CustomObject(${this.value})`
  }
}

const obj = new CustomObject("hello")
console.log(obj) // Displays: CustomObject(hello)
symbols
export const NodeInspectSymbol = Symbol.for("nodejs.util.inspect.custom")

/**
 * The type of the Node.js inspection symbol used for custom object inspection.
 * This symbol type is used to implement custom inspection behavior in Node.js
 * environments.
 *
 * **When to use**
 *
 * Use to type methods keyed by the Node.js custom inspection symbol.
 *
 * **Example** (Typing custom Node inspection)
 *
 * ```ts
 * import { Inspectable } from "effect"
 *
 * class CustomObject {
 *   constructor(private value: string) {}
 *
 *   [Inspectable.NodeInspectSymbol]() {
 *     return `CustomObject(${this.value})`
 *   }
 * }
 *
 * const obj = new CustomObject("test")
 * console.log(obj) // CustomObject(test)
 * ```
 *
 * @category symbols
 * @since 2.0.0
 */
export type NodeInspectSymbol = typeof NodeInspectSymbol
Referenced by 4 symbols