• Error
  • Reported by the binder

TS1101

'with' statements are not allowed in strict mode.

A `with` statement is used in strict-mode code, which includes every module and class. Replace it with explicit property access.

What it means

with adds an object's properties to the scope. It's forbidden in strict mode, and modules and classes are always strict, so in practice it's an error in almost all TypeScript code.

Example

index.ts
const o = { a: 1 };
with (o) {}
export {};
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(2,1): error TS1101: 'with' statements are not allowed in strict mode.

Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.

How to fix

  • Read the properties explicitly: o.a.
  • Use destructuring to get short names: const { a } = o;.