How to fix Argument of type 'never' is not assignable to parameter of type 'any' in TypeScript
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] || '');- Check for untyped empty arrays or collections
- Review type narrowing logic in conditionals
- Explicitly type function parameters with generic constraints
- Use type guards to prevent 'never' inference
// Error: Argument of type 'never' is not assignable to parameter of type 'any'const items = [];process.stdout.write(items[0]);// Fix: Explicitly type the arrayconst 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
- 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
- Generic type constraints that collapse to 'never'
- 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'"
When you declare an empty array without a type annotation, TypeScript infers it as never[]. Explicitly type the array:
// 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.
If you're using if/else or switch statements to narrow types, ensure the remaining type isn't 'never':
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));
}
}If you're using generics that can collapse to 'never', provide explicit type constraints:
// 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);
}When filtering or transforming data, ensure TypeScript doesn't infer 'never':
// 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 inferredIf you've confirmed your logic is correct and this is a legitimate use case, you can use a type assertion:
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 errorType 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
- 📚TypeScript Official Documentation
- 📝
- 📖TypeScript Generics documentation(Official Docs)
- 📖TypeScript Type Compatibility documentation(Official Docs)
- 📝