• Sound mode S-04, pre-alpha
  • Design record 0007, Accepted

TSR0402

{0} (sound mode enables 'exactOptionalPropertyTypes': write '{1}?: 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.

Rule S-04: Checked index access and exact optional properties (level: strict). Reported by ts-r-check and ts-r-lsp in files that opt in to sound mode. See Sound mode.

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

Spec case from design record 0007 (checked by the record's case harness, not by this site's build)
// 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 (accepted 2026-10-15).