-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Search Terms:
super, this and variations of "'super' must be called before accessing 'this' in the constructor of a derived class."
Code
export class Foo {
constructor(value: number) {
}
}
export class BarCorrectlyFails extends Foo {
constructor(something: boolean) {
if (!something) {
const value = this.bar(); // <--- this used before super; correctly detected
super(value);
} else {
super(1337);
}
}
bar(): number { return 4; }
}
export class BarIncorrectlyWorks extends Foo {
constructor(something: boolean) {
if (something) {
super(1337);
} else {
const value = this.bar(); // <--- this used before super; not detected
super(value);
}
}
bar(): number { return 4; }
}Expected behavior:
Both of the above Bar* classes should fail to compile. The branches seem to be ignored when determining if this and super are called in-order, so the above super call in another branch seems to allow compilation to continue.
Actual behavior:
The BarIncorrectlyWorks produces ESM code which fails at runtime, when the super occurs before the this.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue