• Extend a class with a decorate(ClassName) to create a decorator class that accepts any original target of T and returns a decorated class that by default redirects all calls to the target of the decorator (called inner) and allows the decorator itself to extend the original class overriding any function.

    The benefit of this is that you don't need ot manually redirect all calls not decorated to the decorator and that you don't need to define an interface.

    This class is fully TS compatible and will provided valid TypeScript type hinting about the decorated class, the inner class property as well as

    Sample:

    class Foo { 
    constructor(public name: string) { }
    getName() { return `Foo's name: ${this.name}` }
    }

    class FooDecorator extends decorate(Foo) {
    getName() { return `Foo's Decorated name: ${this.name?.toUpperCase()}` }
    }

    const foo = new FooDecorator(new Foo('bar'));
    foo.getName();

    Type Parameters

    • T extends Constructor

    Parameters

    • classProto: T

      Class prototype to decorate

    Returns (new (inner) => InstanceType<T> & Decorator<T>)

      • new (inner): InstanceType<T> & Decorator<T>
      • Parameters

        • inner: InstanceType<T>

        Returns InstanceType<T> & Decorator<T>