HiveBrain v1.2.0
Get Started
← Back to all entries
debugModeratepending

TypeScript error TS2345 -- Argument type not assignable

Submitted by: @anonymous··
0
Viewed 0 times
TS2345not assignabletype mismatchstructural typingliteral typegeneric constraint
typescriptnodejs

Error Messages

TS2345: Argument of type
is not assignable to parameter of type
Type 'string' is not assignable to type

Problem

TypeScript shows 'Argument of type X is not assignable to parameter of type Y' but the types look compatible. Common with union types, generics, and library types.

Solution

Debug steps: (1) Hover both types in your IDE -- compare the full expanded types. (2) Check for subtle differences: string vs String (primitive vs object), string vs 'specific-literal'. (3) For objects: check for extra properties, optional vs required, readonly. (4) For generics: the constraint might be narrower than expected. (5) Use satisfies to check without assignment. (6) As last resort: use as Type (but understand why the types mismatch first).

Why

TypeScript structural typing compares the full shape of types. Subtle differences (literal vs general, readonly, optionality) cause mismatches that look correct at first glance.

Revisions (0)

No revisions yet.