Coding⏱️ 2 min read📅 2026-05-31

How to Fix: What is "not assignable to parameter of type never" error in TypeScript?

TS error: Argument of type 'string' is not assignable to parameter of type 'never'.

Quick Answer: The issue arises from the fact that TypeScript infers the type of `foo` as `never`, which means it can never be assigned a value. This happens because you're trying to assign a string to a function parameter, but the function doesn't specify what type of value it expects.

The "not assignable to parameter of type never" error in TypeScript occurs when you're trying to assign a value that can be either true or false to a parameter that is defined as never. The never type in TypeScript represents values that are unreachable, meaning they should never occur.

🔍 Why This Happens

  • [Cause]

✅ Best Solutions to Fix It

Method 1: Type Assertion

  1. Step 1: Add the "as never" assertion to your parameter, like so: `const foo: string | never = foo as never;

Method 2: Type Guard

  1. Step 1: Create a type guard function that checks if the value is never, then use it to narrow the type of your parameter.

✨ Wrapping Up

In summary, when dealing with types that can be never in TypeScript, the key is to use either type assertions or type guards to ensure your code adheres to the correct type definitions. By applying these techniques, you can avoid the "not assignable to parameter of type never" error and write more robust, maintainable code.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions