How to fix Argument of type 'never' is not assignable to parameter of type 'any' in TypeScript

TypeScriptINTERMEDIATEMEDIUMUpdated Dec 8, 2025· 126 views

This error occurs when TypeScript's type system prevents you from passing a 'never' type value to a function parameter, even if that parameter accepts 'any'. The 'never' type represents an impossible value, and TypeScript's variance rules prevent it from being assigned to parameters.

Quick fix

Fixes Argument of type 'never' is not assignable to parameter of type 'any'

// Error: Argument of type 'never' is not assignable to parameter of type 'any'
const items = [];
process.stdout.write(items[0]);

// Fix: Explicitly type the array
const items: string[] = [];
process.stdout.write(items[0] || '');
  1. Check for untyped empty arrays or collections
  2. Review type narrowing logic in conditionals
  3. Explicitly type function parameters with generic constraints
  4. Use type guards to prevent 'never' inference
typescript — error
// Error: Argument of type 'never' is not assignable to parameter of type 'any'
const items = [];
process.stdout.write(items[0]);
// Fix: Explicitly type the array
const items: string[] = [];
process.stdout.write(items[0] || '');
Argument of type 'never' is not assignable to parameter of type 'any'

What this error means

The 'never' type is TypeScript's bottom type—a type that represents an impossible or unreachable state. It's the only type that has no values. When you encounter this error, it means you're trying to pass a value inferred as 'never' to a function parameter. Even though 'any' is permissive in TypeScript's type system, there's a strict rule: 'never' cannot be assigned to 'any' in function parameters due to contravariance. Function parameters are contravariant, meaning they enforce stricter rules on input types. This is a deliberate design choice that prevents you from accidentally passing impossible values where actual values are expected. This error typically indicates a logic problem in your code—you have code that should be unreachable or a type inference issue that needs fixing.

Typical symptoms

  • TypeScript compiler error when passing a value to a function parameter
  • The value has been inferred as 'never' type by TypeScript
  • Error appears even though the parameter type is 'any'
  • Often occurs after conditional checks that narrow types to impossible states

Common causes

  1. Empty array or object with no explicit type annotation (TypeScript infers 'never' for empty generics)
  2. Exhaustive type narrowing that results in no possible types remaining
  3. Function parameter type that rejects 'never' due to contravariance rules
  4. Generic type constraints that collapse to 'never'
  5. Using a value from a switch or conditional where all branches are handled but TypeScript still sees a 'never' case

How to fix "Argument of type 'never' is not assignable to parameter of type 'any'"

1Check for untyped empty arrays or collections

When you declare an empty array without a type annotation, TypeScript infers it as never[]. Explicitly type the array:

typescript
// Error: Argument of type 'never' is not assignable to parameter of type 'any'
const items = [];
process.stdout.write(items[0]);

// Fix: Explicitly type the array
const items: string[] = [];
process.stdout.write(items[0] || '');

This is the most common cause. Always provide explicit types for empty arrays, especially when they'll be used in function calls.

2Review type narrowing logic in conditionals

If you're using if/else or switch statements to narrow types, ensure the remaining type isn't 'never':

typescript
function process(value: string | number) {
  if (typeof value === 'string') {
    console.log(value.toUpperCase());
  } else if (typeof value === 'number') {
    console.log(value.toFixed(2));
  } else {
    // Here, 'value' is typed as 'never' because all cases are handled
    // Don't pass 'value' to functions expecting 'any'
    someFunction(value);  // Error!
  }
}

// Fix: Ensure the else clause is truly unreachable, or rethink the logic
function process(value: string | number) {
  if (typeof value === 'string') {
    console.log(value.toUpperCase());
  } else {
    // 'value' is number here
    console.log(value.toFixed(2));
  }
}
3Explicitly type function parameters with generic constraints

If you're using generics that can collapse to 'never', provide explicit type constraints:

typescript
// This might infer 'never' in some cases
function handler<T>(value: T) {
  console.log(value);
}

// If called with incompatible types, T becomes 'never'
// Instead, use explicit typing
const result: string = someGenericFunc<string>();

// Or provide a fallback/default type
function handler<T = unknown>(value: T) {
  console.log(value);
}
4Use type guards to prevent 'never' inference

When filtering or transforming data, ensure TypeScript doesn't infer 'never':

typescript
// Problematic: TypeScript might infer 'never' for filtered values
const values = [1, 2, 3];
const filtered = values.filter(v => v > 10);  // Empty array inferred as 'never[]'

// Fix: Explicitly type the result
const filtered: number[] = values.filter(v => v > 10);

// Or use a type guard function
function isValid(v: unknown): v is string {
  return typeof v === 'string';
}
const strs = values.filter(isValid);  // Correctly inferred
5Cast to 'any' only as a last resort

If you've confirmed your logic is correct and this is a legitimate use case, you can use a type assertion:

typescript
const value: never = somethingImpossible();
// Only use as a last resort
someFunction(value as any);

// Better: Question why you have a 'never' type in the first place
// This usually indicates a logic error

Type assertions should be rare. If you're using them frequently for this error, reconsider your type design.

Advanced notes

This error relates to TypeScript's contravariance principle for function parameters. When you assign a function to another function type, the parameter types must be "larger" or more general than the original. Since 'never' is the smallest possible type (the bottom type), it fails contravariance checks.

Understanding this helps you see why the error exists: if a function accepts 'never' parameters, it's saying "I can only be called with impossible values," which is useful for exhaustiveness checking but means the function can never actually be called in practice.

In strict mode, TypeScript enforces this rule rigorously. If you're using 'any' to bypass type checking, consider whether your type design needs refinement instead.

Frequently asked questions

What does "Argument of type 'never' is not assignable to parameter of type 'any'" mean?
The 'never' type is TypeScript's bottom type—a type that represents an impossible or unreachable state. It's the only type that has no values. When you encounter this error, it means you're trying to pass a value inferred as 'never' to a function parameter.
How do I fix "Argument of type 'never' is not assignable to parameter of type 'any'"?
This error occurs when TypeScript's type system prevents you from passing a 'never' type value to a function parameter, even if that parameter accepts 'any'. The 'never' type represents an impossible value, and TypeScript's variance rules prevent it from being assigned to parameters.
What causes "Argument of type 'never' is not assignable to parameter of type 'any'"?
Empty array or object with no explicit type annotation (TypeScript infers 'never' for empty generics) Exhaustive type narrowing that results in no possible types remaining Function parameter type that rejects 'never' due to contravariance rules
Is the "Argument of type 'never' is not assignable to parameter of type 'any'" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading