- Sound mode S-08, pre-alpha
- Design record 0007, Accepted
TSR0803
'this' escapes from the constructor through '{0}' before subclass fields are initialised. Make it '#private', or do this after construction (a static factory).
A constructor calls an overridable method or passes 'this' out, before subclass fields exist. Make the method #private or use a static factory.
Rule S-08: Fields are initialised before `this` escapes (level: sound). Reported by ts-r-check and ts-r-lsp in files that opt in to sound mode. See Sound mode.
What it means
A subclass's fields aren't initialised until the base constructor returns, so a base constructor that calls a method a subclass can override (or passes this out) can run subclass code on a half-built object. #private and private members are allowed, because their bodies are checked by the same rule.
Example
// A base constructor calls a method a subclass can override.
class Base {
constructor() {
this.setup(); // @expect TSR0803
}
setup(): void {
console.log("base");
}
}
new Base();
export {};
How to fix
- Make the helper
#private. - Replace two-phase initialisation with a static factory that constructs, then calls the setup method.
Sound mode is defined in design record 0007 (accepted 2026-10-15).