An interface merge can be used to "add" new functionality to an existing class (as long as only public features are accessed):
class MyClass { readonly #value: number; constructor(value: number) { this.#value = value; } get value():number { return this.#value; } } interface MyClass { square():number; } function square(this:MyClass): number { const value = this.value; return value * value; } MyClass.prototype.square = square; const container = new MyClass(42); console.assert(container.square() === 1764, "Square isn't 1764");
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
An interface merge can be used to "add" new functionality to an existing class (as long as only public features are accessed):