• Error
  • Reported by the type checker

TS1042

'{0}' modifier cannot be used here.

A modifier is written somewhere it has no meaning, such as `public` on an object literal property. Remove the modifier.

What it means

Modifiers like public, static, readonly or export only make sense on certain declarations. This code reports one used elsewhere, for example on a property or method of an object literal, where no modifier except async (on methods) is allowed.

Example

index.ts
export const point = { public x: 1 };
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(1,24): error TS1042: 'public' modifier cannot be used here.

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

  • Delete the modifier.
  • If you wanted a class with that visibility, declare a class instead of an object literal.