Home/TypeScript Errors/TS2345
Argument of type 'X' is not assignable to parameter of type 'Y'
TypeScript TS2345 fires when you pass a value to a function whose type does not match the expected parameter type. The type system cannot prove the argument is safe to use in that position.
Why This Happens
You are passing a value of type A to a function that expects type B, and A is not assignable to B — for example, passing a string where a number is required, or a broader union type where a narrower type is expected.
Code That Triggers TS2345
// TS2345 examples
function greet(name: string): string {
return "Hello, " + name;
}
greet(42);
// Error: Argument of type 'number' is not assignable to parameter of type 'string'
// Also common with unions
function process(id: number): void {}
const value: string | number = getValueFromAPI();
process(value);
// Error: Argument of type 'string | number' is not assignable to parameter of type 'number'How to Fix TS2345
Option 1: Narrow the type before passing
const value: string | number = getValueFromAPI();
if (typeof value === "number") {
process(value); // OK — narrowed to number
}Option 2: Cast with 'as' when you're certain
process(value as number); // use only when you know it's safeOption 3: Fix the function signature to accept the actual type
function process(id: number | string): void {
const normalized = Number(id);
}Frequently Asked Questions — TS2345
What does TS2345 mean?
TypeScript TS2345 means the value you're passing to a function doesn't match the type the function declared it would accept. TypeScript's type system prevents this at compile time to catch bugs before they reach runtime.
How do I fix TS2345 without 'any'?
Narrow the type with typeof, instanceof, or a type guard before passing the value. Alternatively, broaden the function's parameter type to accept the actual type you're passing.
Why does TS2345 happen with string | number unions?
A union type like string | number is wider than number alone. TypeScript won't let you pass a wider type where a narrower one is required — you must first narrow it (e.g., with typeof value === 'number') to guarantee safety.
Is it safe to use 'as' to suppress TS2345?
Only if you can guarantee at runtime that the value is the correct type. Using 'as' bypasses type checking — if the value is actually the wrong type, you'll get a runtime error instead of a compile-time one.
Can TS2345 happen with React props?
Yes. If you pass the wrong prop type to a React component — for example, a string where a number is expected — TypeScript reports TS2345. Fix by matching the prop type or updating the component's prop interface.
Convert JavaScript to TypeScript automatically
Paste your JS code and get type-annotated TypeScript — including fixes for common type errors — in seconds.
Try the converter →Other TypeScript Errors
From the blog
View all →
Jun 11, 2026
Tailwind CSS to CSS: Expand Utility Classes Back to Standard CSS

Jun 11, 2026
JSON to Zod Schema: Runtime Type Validation for TypeScript

Jun 8, 2026
JavaScript Object to JSON: Serialization Patterns and Common Pitfalls

Jun 8, 2026
TypeScript to JavaScript: When and How to Strip Types

Jun 4, 2026
JavaScript Object to JSON: Serialization Patterns and Common Pitfalls