This error means the TypeScript compiler found a variable, function, class, or interface that you declared but never actually used anywhere in your code.

This is a common issue, and it usually stems from a few specific scenarios:

Unused Imports

This is by far the most frequent culprit. You import something from a library or another module, but you don’t end up using it.

Diagnosis: Look at your import statements. Are there any that don’t have a corresponding usage in the code below them?

Fix: Delete the unused import line. For example, if you have:

import { unusedFunction } from './utils';
import { usedFunction } from './utils';

console.log(usedFunction());

You would remove the line import { unusedFunction } from './utils';.

Why it works: The compiler sees unusedFunction being imported but never referenced. Removing the import tells the compiler that this symbol is no longer relevant to the current scope, satisfying the check.

Unused Local Variables

You declare a variable within a function or block scope but never assign a value to it or read from it.

Diagnosis: Scan your functions and code blocks for variable declarations (let, const, var) that are immediately followed by other code without any reference to the declared variable.

Fix: Remove the unused variable declaration. For instance:

function processData(data: string) {
  const processedData = data.toUpperCase();
  const intermediateValue = 10; // This is unused
  console.log(processedData);
}

Here, you’d remove const intermediateValue = 10;.

Why it works: The compiler detects that intermediateValue was declared but never read from. Removing the declaration eliminates the unused symbol.

Unused Function Parameters

A function is defined with parameters, but some of those parameters are never referenced within the function body.

Diagnosis: Examine function signatures and their bodies. Identify parameters that don’t appear in the function’s logic.

Fix: Prepend the parameter name with an underscore (_). This is a convention that signals to TypeScript (and other developers) that the parameter is intentionally unused.

function handleEvent(event: Event, _metadata: any) { // _metadata is intentionally unused
  console.log(event.type);
}

Alternatively, you can remove the parameter entirely if it’s truly not needed, but the underscore is useful when you might need it later or want to maintain a consistent function signature.

Why it works: TypeScript treats parameters prefixed with _ as intentionally unused, suppressing the error for those specific parameters.

Unused Class Members

You define properties, methods, or getters/setters within a class that are never accessed from outside the class or by other methods within the same class.

Diagnosis: Review your class definitions. Look for members that don’t have any calls or assignments associated with them from other parts of your application or even within the class itself.

Fix: You have a few options:

  1. Remove the member: If it’s truly dead code, delete it.
  2. Prefix with _: Similar to function parameters, _privateMember can indicate intentional non-usage, though it’s less common for public members.
  3. Mark as public readonly if it’s a constant: If it’s a value that’s set in the constructor and never changed, marking it readonly can sometimes satisfy the compiler if it’s being read by external code.
class User {
  public name: string;
  private age: number; // Unused
  public constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
  }

  public greet() {
    console.log(`Hello, ${this.name}`);
  }
}

In this case, private age: number; would trigger the error. You would remove it or, if it were intended to be used later, ensure it’s accessed.

Why it works: The compiler flags unused class members because they can indicate leftover code or potential logic errors. Removing or marking them appropriately resolves the redundancy.

Unused Enum Members

Enums can also have members that are declared but never referenced.

Diagnosis: Check your enum definitions for members that are not used in any switch statements, conditional checks, or assignments.

Fix: Remove the unused enum member.

enum Status {
  Pending = 'PENDING',
  Processing = 'PROCESSING',
  Completed = 'COMPLETED',
  Failed = 'FAILED', // Unused
}

function getStatusMessage(status: Status): string {
  switch (status) {
    case Status.Pending:
      return 'Operation is pending.';
    case Status.Processing:
      return 'Operation is in progress.';
    case Status.Completed:
      return 'Operation completed successfully.';
    default:
      return 'Unknown status.';
  }
}

You’d remove Failed = 'FAILED', from the enum.

Why it works: Similar to other declarations, an unused enum member represents a symbol that isn’t contributing to the program’s logic.

Unused Exported Declarations

When you export a variable, function, class, or interface, TypeScript assumes it might be used by other modules. If it’s exported but never imported or used anywhere, it will also trigger this error. This is particularly common in library development or when refactoring modules.

Diagnosis: Look at your export statements. If a symbol is exported but you can’t find any import statements in other files that reference it, that’s the likely cause.

Fix:

  1. Remove the export keyword: If the symbol is only meant for internal use within its own module, remove export.
  2. Delete the declaration: If the symbol is neither used internally nor intended for external use, remove it entirely.
// utils.ts
export const internalHelper = () => { /* ... */ }; // Unused export
export const publicApiFunction = () => { /* ... */ };

// main.ts
import { publicApiFunction } from './utils';
publicApiFunction();

In utils.ts, you would remove export from internalHelper.

Why it works: The compiler flags unused exports because they can clutter the public API of a module and indicate potential oversights. Removing the export makes the declaration local to its module, satisfying the check.

Once you’ve cleared up all instances of TS6133, you might then encounter TS2305: Module '"…"' has no exported member '…' if you’ve accidentally removed an export that was actually needed elsewhere.

Want structured learning?

Take the full Typescript course →