error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'
TypeScript
error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'.
What it means (root cause)
You passed a value whose type does not match the function's declared parameter type — often because the value is wider (string | undefined) than expected, or the shapes differ.
The symptom developers actually see: error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'.
Step-by-step fix
Concrete, ordered steps from the dataset. Apply them in order; each line is a verified action, not generic advice.
- 1Read the two types the compiler printed; the mismatch is usually a missing property or a wider union.
- 2Narrow the value: guard undefined, or cast only when certain (value as Expected).
- 3If the function signature is wrong, tighten it instead of casting every call site.
Where this error appears
Languages, frameworks, and runtimes where this error is observed (from the 2026 DevFixPro error dataset, retrieved 2026-08-29):
TypeScript 3.x–5.x, any build (tsc, vite, webpack, next). It is a compile-time error — the code never runs until it is fixed.
How to prevent it & common questions
Practical prevention plus the questions developers ask most about this error.
What does "error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'" mean?
You passed a value whose type does not match the function's declared parameter type — often because the value is wider (string | undefined) than expected, or the shapes differ.
Which environments are affected by error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'?
TypeScript
How do I fix error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'?
Read the two types the compiler printed; the mismatch is usually a missing property or a wider union. Narrow the value: guard undefined, or cast only when certain (value as Expected). If the function signature is wrong, tighten it instead of casting every call site.
How do I prevent error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'?
Keep function parameter types precise and avoid any; let the compiler localize mismatches instead of casting them away.
Why does it say 'not assignable to parameter of type'?
The argument's type is incompatible with the parameter the function declares. The compiler prints both types; align them at the call site or in the signature.
Is casting with 'as' safe?
Only when you are certain the value really is that type. Casting hides the error; narrowing (guards) keeps the safety.
Related DevFixPro tools
Real, browser-only utilities on DevFixPro that help while you work through this issue. These are navigation aids, not a substitute for the fix above.
Sources & attribution
- Error records aggregated from Google Search Console query gaps (2026-05-21~2026-08-18) for devfixpro.com, plus official framework docs (MDN, Node.js docs, Python docs, Go.dev, Rust book, Oracle Java docs, Docker docs, npm docs). Source dataset retrieved 2026-08-29. License: CC BY 4.0 — attribute DevFixPro (devfixpro.com).
- Official reference: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
- All cause, environment, fix and prevention text on this page is taken verbatim from the DevFixPro 2026 error dataset. DevFixPro does not invent root causes or fixes.
How this error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y' page is built
Each error page is generated from a single record in the DevFixPro 2026 error dataset. The meaning, root cause, environments, fix steps, prevention, and official references are copied verbatim from that dataset and its official-doc sources; related-error links are computed from the error's category and explicit peer list. No root cause or fix is invented. The retrieval date for this dataset is 2026-08-29.