• Error
  • Reported by the type checker

TS2352

Conversion of type '{0}' to type '{1}' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.

A type assertion (`as`) converts between two types that don't overlap at all, which is probably a mistake. Fix the value, or go through `unknown`.

What it means

x as T is allowed when either type is assignable to the other. When the two types have nothing in common, the assertion is almost certainly wrong, so it's reported.

Example

index.ts
const id = 42;

export const s = id as string;
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(3,18): error TS2352: Conversion of type 'number' to type 'string' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.

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

  • Convert the value instead: String(id).
  • If you really mean it, assert through unknown: id as unknown as string. That tells the checker to trust you; nothing checks it at runtime.