# TypeScript: “Argument of type 'X' is not assignable to parameter of type 'Y'” (TS2345)

> TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Narrow the value, fix the type at its source, or use as const.

Canonical: https://app369.com/fix/typescript-argument-of-type-is-not-assignable-to-parameter/
Last updated: 2026-11-08

The compiler stops with error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string' (or 'string' is not assignable to '"GET" | "POST"', or an object type that is missing properties). The value you pass into a function could be something the function does not accept. TypeScript reports it at the call, but the fix is often where the value was created.

**Short answer**

Read the two types in the message. If the argument includes undefined or null, check for it before the call or give a default. If it is string where a set of literal strings is expected, keep the literal type with as const or a type annotation. If it is an object, the indented lines under the error name the property that is missing or has the wrong type. Avoid as casts that only silence the error: they move the crash to runtime.

## **Why the types do not match, and the fix**

1. 01 ### **undefined or null in the argument** Optional props, find(), environment variables and form values can all be undefined. Handle that case before the call, so the type inside the if is the plain type.```
const apiUrl = process.env.API_URL;
if (!apiUrl) throw new Error('API_URL is not set');
connect(apiUrl); // string, not string | undefined
```
2. 02 ### **A string where specific strings are expected** let method = 'GET' widens to string, which a parameter typed 'GET' | 'POST' rejects. Use const, as const, or annotate the variable with the union.```
type Method = 'GET' | 'POST';
const method: Method = 'GET';

const options = { method: 'GET' } as const;
```
3. 03 ### **An object that is missing a property or has the wrong shape**
  > “The basic rule for TypeScript’s structural type system is that x is compatible with y if y has at least the same members as x.” [**TypeScript, Type compatibility**](https://www.typescriptlang.org/docs/handbook/type-compatibility.html) TypeScript compares objects by their members. The lines under the error show the first property that does not fit. Add it, fix its type, or change the parameter type if the function really accepts less.
4. 04 ### **React event and ref types** Passing a handler typed for one element to another (ChangeEvent<HTMLInputElement> on a select) or a ref of the wrong element type gives the same kind of mismatch. In JSX it is reported as TS2322 on the prop; TS2345 appears when you call the handler yourself. Type the handler for the element it is attached to.```
const onChange = (e: React.ChangeEvent<HTMLSelectElement>) => setPlan(e.target.value);
```

Checked against the vendor’s docs on November 8, 2026: [TypeScript Handbook: Type compatibility](https://www.typescriptlang.org/docs/handbook/type-compatibility.html); [TypeScript Handbook: Narrowing](https://www.typescriptlang.org/docs/handbook/2/narrowing.html).

## **Rather hand it over?**

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

- [from $450**App Fix Ticket**One reproducible bug in an existing mobile or web app, diagnosed and fixed.**See scope and start**](https://app369.com/fixed-price/flutter-firebase-bug-fix/)
- [from $450**AI-Built App Rescue**A Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.****No issues worth fixing, no charge.**** If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.**See scope and start**](https://app369.com/fixed-price/ai-app-rescue/)

Related: [**TypeScript “Type is not assignable to type”**](https://app369.com/fix/typescript-type-is-not-assignable-to-type/) · [**TypeScript “Object is possibly null”**](https://app369.com/fix/typescript-object-is-possibly-null/) · [**TypeScript “Property does not exist on type”**](https://app369.com/fix/typescript-property-does-not-exist-on-type/)

Questions

## **More on this error**

<details>

<summary>**What is the difference from Type is not assignable to type? **+</summary>

Same check, different place. TS2322 is reported on an assignment or return; TS2345 is reported on a function argument. The fixes are the same.

</details>

<details>

<summary>**Is as string a good fix? **+</summary>

Only when you know something TypeScript cannot, such as a value checked elsewhere. Otherwise the cast hides a real undefined that will crash at runtime.

</details>

<details>

<summary>**Can you fix it for me? **+</summary>

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

</details>

A different error?

## **Describe it and get a written quote**

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.

[**Describe your problem **→](https://app369.com/contact/) [**All fixes**](https://app369.com/fix/)