Masner
10/18/2017 - 4:54 PM

Extendovaní implicitního typu v typescriptu

Bohužel to už nefunguje, a musí se přidat javascriptová fligna do konstruktoru https://github.com/Microsoft/TypeScript/wiki/FAQ#why-doesnt-extending-built-ins-like-error-array-and-map-work

// DO NOT WORK ANY MORE
class FooError extends Error {
    constructor(m: string) {
        super(m);
    }
    sayHello() {
        return "hello " + this.message;
    }
}

// HAS TO BE LIKE THIS FROM NOW ON
class FooError extends Error {
    // MAGIC
    constructor(m: string) {
        super(m);

        // Set the prototype explicitly.
        Object.setPrototypeOf(this, FooError.prototype);
    }

    sayHello() {
        return "hello " + this.message;
    }
}