# TSR0802: 'this' escapes before '…' is initialised. Assign every field first.

> 'this' is passed out, used to call a method, or captured before every field is assigned. Assign every field first.

## What it means

Until every field is definitely assigned, a constructor or field initialiser may only use `this` to assign a field or read one already assigned. Calling a method or accessor on `this`, passing `this` as an argument, storing or returning it, or creating an arrow function that mentions it lets other code see an object with missing fields. Optional fields and fields whose type includes `undefined` count as assigned from the start.

## Example

```ts
// Registering this before its id is set.
const registry = new Set<object>();
class Entity {
  id: string;
  constructor(id: string) {
    registry.add(this); // @expect TSR0802
    this.id = id;
  }
}
new Entity("a");
export {};
```

## How to fix

- Assign every field before the first use of `this` other than field assignments.
- Initialise fields in their declarations where possible.

Sound mode is defined in [design record 0007](https://github.com/Webb-Ventures/typescript-rust/blob/main/docs/design/0007-sound-mode.md) (accepted 2026-10-15).

Source: https://ts-r.dev/errors/TSR0802/
