Microsoft/TypeScript

No compile error thrown when `this` referenced before call to `super` completes

Open

#8.060 geöffnet am 13. Apr. 2016

Auf GitHub ansehen
 (13 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
Effort: DifficultHelp WantedSuggestion

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

TypeScript Version:

1.8.9

Code JSFiddle: https://jsfiddle.net/kitsonk/fs9t96ep/ TS Playground: http://goo.gl/X7cgvV

class A {
    constructor(fn: () => void) {
        fn.call(this);
    }
    foo: string = 'foo';
}

class B extends A {
    constructor() {
        super(() => {
            console.log(this);
        });
    }
    bar: string = 'bar';
}

const b = new B();

Expected behavior: Typescript should guard against the use of this as the call to super has not completed. Thus it should not compile.

Actual behavior: Typescript compiles this successfully. It works fine when the target is set to es5 but breaks the browser when target is set to es6. Error is: VM89:55 Uncaught ReferenceError: this is not defined

Contributor Guide