ProjectStack
typescript

TS2352: Conversion of type 'X' to type 'Y' may be a mistake

You're using a type assertion (the as keyword) to convert a value between two types that don't share enough overlap for TypeScript to consider it safe. TypeScript flags this because the conversion looks like an error rather than intentional casting.

Common causes

  • Asserting a type that has no overlap with the actual type (e.g., number as string)
  • Using as to convert between completely unrelated types to bypass type checking
  • Incorrect type narrowing where the assertion doesn't logically follow from the runtime type
  • Mistakenly swapping the source and target types in an assertion

How to fix it

  1. Check if the assertion makes sense — if the types don't overlap, the assertion is likely wrong
  2. Use unknown as an intermediate if you must assert between unrelated types: (value as unknown) as TargetType
  3. Prefer type guards over assertions: use typeof, instanceof, or a custom type predicate
  4. Review whether you need the assertion at all — restructuring the code to avoid it is safer

Example

const num = 42; const str = num as string; // error TS2352: Conversion of type 'number' to type 'string' may be a mistake because neither type sufficiently overlaps with the other.

Asserting a number as string — these types have no overlap so TypeScript flags the cast

Browse more errors

The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.