Tersiblized
function Tersiblized<C extends new (...args: any[]) => object>( Base: C, tersify: (this: InstanceType<C>, options?: Partial<TersifyOptions>) => string): C & (new (...args: any[]) => { tersify(options?: Partial<TersifyOptions>): string })Returns a subclass of Base with a tersify() method. Base itself is untouched — this is the
non-mutating counterpart to tersible.
Parameters
Section titled “Parameters”| Parameter | Type | Meaning |
|---|---|---|
Base |
a constructor | The class to extend |
tersify |
(this: InstanceType<C>, options?) => string |
The representation, called with this bound to the instance |
Example
Section titled “Example”import { Tersiblized } from 'tersify'
class Foo { a = 1}
class Boo extends Tersiblized(Foo, function () { return `a = ${this.a}`}) {}
const b = new Boo()b.a = 2b.tersify() // "a = 2"The method is evaluated on every call, so it reflects the instance’s current state.
Because the result is an ordinary class, it composes the way any base class does — extend it
directly, or extends Tersiblized(Base, fn) inline as above.
Choosing between the helpers
Section titled “Choosing between the helpers”| Mutates | Use when | |
|---|---|---|
tersible |
yes | You are handed a value at runtime |
Tersiblized |
no | You control the class definition |
A plain tersify() method |
no | You control the class and want no dependency in the signature |
All three produce the same Tersible shape, and
tersify() treats them identically.