Hyperlinkv0.8.0-beta.28

Inspectable

Inspectable.BaseProtoconsteffect/Inspectable.ts:232
Inspectable

A base prototype object that implements the Inspectable interface.

When to use

Use as a prototype for plain objects that should share standard inspectable behavior.

Details

This object provides default implementations for the Inspectable methods. It can be used as a prototype for objects that want to be inspectable, or as a mixin to add inspection capabilities to existing objects.

Example (Using the base inspectable prototype)

import { Inspectable } from "effect"

// Use as prototype
const myObject = Object.create(Inspectable.BaseProto)
myObject.name = "example"
myObject.value = 42

console.log(myObject.toString()) // Pretty printed representation

// Or extend in a constructor
function MyClass(this: any, name: string) {
  this.name = name
}
MyClass.prototype = Object.create(Inspectable.BaseProto)
MyClass.prototype.constructor = MyClass
prototypesInspectable
export const BaseProto: Inspectable = {
  toJSON() {
    return toJson(this)
  },
  [NodeInspectSymbol]() {
    return this.toJSON()
  },
  toString() {
    return format(this.toJSON())
  }
}