Fixing TypeScript Error: Argument of type 'string' is not assignable to parameter of type 'never'

beginner๐Ÿ”ต TypeScript2026-04-01| TypeScript 3.0+ | Node.js | VS Code | React 16.8+

Error Message

Argument of type 'string' is not assignable to parameter of type 'never'.
#typescript#web-development#react#coding-tips

The ProblemWe've all been there. You initialize an empty array, try to .push() a simple string, and TypeScript suddenly hits you with a red squiggly line. Even though the code looks like standard JavaScript, the compiler refuses to cooperate.

const items = [];

// โŒ TypeScript Error
items.push("new item"); 
// Argument of type 'string' is not assignable to parameter of type 'never'.

This happens because TypeScript is trying to guess your intent. When you declare an empty array without a type or initial values, the inference engine assumes the array will always stay empty. To represent this "impossible" state, it assigns the type never[].

Root Cause: Why 'never'?In the TypeScript universe, never is the bottom type. It represents values that should not exist. When you write const items = [];, and provide no context, the compiler plays it safe. It assumes there is a 0% chance this array will ever hold data.

Since nothing can be assigned to never, trying to add a string or a number triggers a type mismatch. You are essentially trying to put something into a box that the compiler has labeled "permanently empty."

Solutions to Fix the Error### 1. Explicit Type AnnotationAssigning a type during initialization is the cleanest fix. It tells the compiler exactly what to expect as the project grows. This is common practice in 90% of professional TypeScript codebases.

// Explicitly define the array as holding strings
const items: string[] = [];

// This works perfectly
items.push("new item");

Working with complex data? Define an interface or type first to keep your code organized:

interface Product {
  id: string;
  price: number;
}

const cart: Product[] = [];
cart.push({ id: "A101", price: 29.99 });

2. Using the Array Generic SyntaxSome teams prefer the Array<T> syntax. While it functions exactly like the square bracket notation, it can be easier to read when dealing with complex nested types.

const tags = new Array<string>();

tags.push("typescript"); // No more error

3. Fixing the React useState HookThis error is a frequent headache for React developers. If you initialize a state hook with an empty array, TypeScript defaults to never[]. You must provide a generic type argument to the hook.

import { useState } from 'react';

// โŒ Incorrect: list is inferred as never[]
const [list, setList] = useState([]); 

// โœ… Correct: explicitly typed
const [list, setList] = useState<string[]>([]);

const addItem = () => {
  setList([...list, "new item"]);
};

4. Type Assertions (Use with Caution)If you are working with legacy code where you can't easily change the declaration, you can use the as keyword. This tells TypeScript to "trust you," but it bypasses some safety checks.

const data = [] as string[];
data.push("safe now");

Handling Multiple Types (Union Types)Sometimes your array needs to be flexible. If you want to store both IDs and names, use a union type. Without this, your code will break the moment you try to add a second data type to a strictly typed array.

// Allow both strings and numbers
const mixedData: (string | number)[] = [];

mixedData.push("User_01");
mixedData.push(550);

How to Verify the FixDon't just trust that the error went away. Follow these steps to be sure:

  • Check the Hover State: Hover your mouse over the variable in VS Code. It should show string[] instead of never[].- Run the Compiler: Open your terminal and run npx tsc. A successful fix will result in zero errors in the build output.- Test Intellisense: Type items.push(. Your IDE should now suggest the correct data type automatically.## Prevention Tips- Avoid naked initializers: Get into the habit of writing const arr: Type[] = []. It takes two seconds and saves minutes of debugging.- Enable Strict Mode: Ensure "strict": true is set in your tsconfig.json. It makes the compiler more pedantic, but it catches inference bugs before they reach production.- Start with data: If you initialize the array with a value, like const names = ["Admin"];, TypeScript will correctly infer the type as string[] without extra effort.

Related Error Notes