# TSR0402: … (sound mode enables 'exactOptionalPropertyTypes': write '…?: T | undefined' to allow 'undefined').

> Sound mode turned on exactOptionalPropertyTypes, so an optional property can't be set to undefined. Omit the key or add '| undefined' to its type.

## What it means

Sound and strict files are checked with `exactOptionalPropertyTypes`: an optional property `p?: T` accepts a missing key, not `undefined`, unless its type includes `undefined`. When only sound mode turns the flag on, tsc's error is reported with this code and tsc's message in `{0}`.

## Example

```ts
// Assigning undefined to an optional field.
class Draft {
  title?: string;
  clear(): void {
    this.title = undefined; // @expect TSR0402
  }
}
new Draft().clear();
export {};
```

## How to fix

- Leave the key out instead of setting it to `undefined` (`delete` it for an existing object).
- Or allow `undefined` explicitly: `title?: string | undefined`.
- Or turn the flag on in tsconfig.json so the error keeps tsc's code.

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/TSR0402/
