How to fix Method 'x' in type 'X' cannot be assigned to the same method in base type 'Y' in TypeScript

TypeScriptINTERMEDIATEMEDIUMUpdated Dec 11, 2025ยท 107 views

This TypeScript error occurs when a derived class attempts to override a method from its base class with an incompatible signature. The method in the derived class must be assignable to the base class method, meaning it should have compatible parameter types and return type. Fixing this involves ensuring method signatures match or using appropriate type annotations.

Quick fix

Fixes Method 'x' in type 'X' cannot be assigned to the same method in base type 'Y'

// Base class
class Animal {
  makeSound(volume: number): string {
    return `Sound at volume ${volume}`;
  }
}

// Derived class with incompatible override
class Dog extends Animal {
  // ERROR: Parameter type mismatch (string vs number)
  makeSound(volume: string): string {
    return `Bark at volume ${volume}`;
  }
}
  1. Check the exact method signature mismatch
  2. Ensure return types are compatible (covariant)
  3. Ensure parameter types are compatible (contravariant)
  4. Match optional/required parameter status
typescript โ€” error
// Base class
class Animal {
makeSound(volume: number): string {
return `Sound at volume ${volume}`;
}
}
// Derived class with incompatible override
class Dog extends Animal {
// ERROR: Parameter type mismatch (string vs number)
makeSound(volume: string): string {
return `Bark at volume ${volume}`;
}
}
Method 'x' in type 'X' cannot be assigned to the same method in base type 'Y'

What this error means

In TypeScript, when a class extends another class, it inherits all methods from the base class. If the derived class defines a method with the same name as a method in the base class, it overrides that method. However, TypeScript enforces strict compatibility rules for method overriding: the overriding method must be assignable to the base method. This means the parameter types should be compatible (contravariant), and the return type should be compatible (covariant). The error occurs when TypeScript detects that the derived class method signature is not compatible with the base class method signature, which could lead to runtime errors if the derived class is used through a base class reference.

Typical symptoms

  • TypeScript compiler error with message "Method 'methodName' in type 'DerivedClass' cannot be assigned to the same method in base type 'BaseClass'"
  • IDEs like VS Code showing red squiggly underlines on the method definition in the derived class
  • Build process fails when compiling TypeScript code with inheritance
  • Error occurs when trying to override a method from a parent class or interface
  • The error message specifies which method name is causing the issue and which classes are involved
  • Code completion and type checking may show mismatches between expected and actual method signatures

Common causes

  1. Changing the return type of an overridden method to an incompatible type
  2. Adding required parameters to an overridden method that the base method does not have
  3. Changing parameter types to incompatible types (e.g., string to number)
  4. Making an optional parameter required in the derived class method
  5. Changing the number or order of parameters in a way that breaks compatibility
  6. Using different generic type constraints in the derived method
  7. Overriding a method with different access modifiers (private, protected, public)
  8. Attempting to override a method that is marked as final or sealed in some way

How to fix "Method 'x' in type 'X' cannot be assigned to the same method in base type 'Y'"

1Check the exact method signature mismatch

Look at the error message to identify which method is causing the issue. Compare the method signature in the base class with the one in the derived class. Check parameter types, return type, and optional/required status.

typescript
// Base class
class Animal {
  makeSound(volume: number): string {
    return `Sound at volume ${volume}`;
  }
}

// Derived class with incompatible override
class Dog extends Animal {
  // ERROR: Parameter type mismatch (string vs number)
  makeSound(volume: string): string {
    return `Bark at volume ${volume}`;
  }
}
2Ensure return types are compatible (covariant)

The return type of the derived method must be assignable to the return type of the base method. You can return a more specific type (subtype) but not a more general type.

typescript
class Base {
  getValue(): Animal {
    return new Animal();
  }
}

class Derived extends Base {
  // OK: Dog is a subtype of Animal
  getValue(): Dog {
    return new Dog();
  }
}

class WrongDerived extends Base {
  // ERROR: Object is not assignable to Animal
  getValue(): Object {
    return {};
  }
}
3Ensure parameter types are compatible (contravariant)

Parameter types in the derived method should be assignable from the base method parameters. You can accept more general types (supertypes) but not more specific types.

typescript
class Base {
  process(animal: Animal): void {
    console.log(animal.name);
  }
}

class Derived extends Base {
  // OK: Object is a supertype of Animal
  process(thing: Object): void {
    console.log(thing.toString());
  }
}

class WrongDerived extends Base {
  // ERROR: Dog is a subtype, not supertype
  process(dog: Dog): void {
    console.log(dog.bark());
  }
}
4Match optional/required parameter status

You cannot make an optional parameter required in the derived class. The derived method can have fewer required parameters (by making them optional) but not more.

typescript
class Base {
  // Optional parameter
  configure(options?: object): void {
    // implementation
  }
}

class Derived extends Base {
  // ERROR: Made optional parameter required
  configure(options: object): void {
    // implementation
  }
}

class CorrectDerived extends Base {
  // OK: Still optional, can add default
  configure(options: object = {}): void {
    // implementation
  }
}
5Use method overloading for complex cases

If you need to support multiple signatures, use method overloading. The implementation signature must be compatible with all overloads.

typescript
class Base {
  process(input: string): string;
  process(input: number): number;
  process(input: string | number): string | number {
    if (typeof input === "string") {
      return input.toUpperCase();
    } else {
      return input * 2;
    }
  }
}

class Derived extends Base {
  // Must support all base overloads
  process(input: string): string;
  process(input: number): number;
  process(input: string | number): string | number {
    // Can add new behavior but must be compatible
    if (typeof input === "string") {
      return `Processed: ${input.toUpperCase()}`;
    } else {
      return input * 3;
    }
  }
}
6Check generic type constraints

If methods use generic types, ensure the constraints are compatible. The derived method can have tighter constraints but not looser ones.

typescript
class Base {
  process<T extends Animal>(item: T): T {
    return item;
  }
}

class Derived extends Base {
  // OK: Dog extends Animal
  process<T extends Dog>(item: T): T {
    return item;
  }
}

class WrongDerived extends Base {
  // ERROR: T extends Object is looser than T extends Animal
  process<T extends Object>(item: T): T {
    return item;
  }
}
7Verify with type assertions if needed

In rare cases where you know the override is safe but TypeScript cannot verify it, you can use type assertions. Use this cautiously as it bypasses type safety.

typescript
class Base {
  process(value: string): string {
    return value;
  }
}

class Derived extends Base {
  // Type assertion to suppress error (use with caution)
  process(value: any): string {
    return String(value);
  }
}

// Better alternative: use a union type
class BetterDerived extends Base {
  process(value: string | number): string {
    return String(value);
  }
}

Advanced notes

TypeScript's method compatibility rules follow the Liskov Substitution Principle (LSP), which states that objects of a superclass should be replaceable with objects of a subclass without affecting program correctness. The contravariant parameter rule and covariant return rule ensure this principle. When debugging these errors, remember that TypeScript uses structural typing, so compatibility is based on shape, not nominal inheritance. For complex inheritance hierarchies, consider using composition over inheritance or the Strategy pattern. The override keyword (available in TypeScript 4.3+) can help catch errors by explicitly marking method overrides, though it doesn't change the compatibility rules.

Frequently asked questions

What does "Method 'x' in type 'X' cannot be assigned to the same method in base t" mean?
In TypeScript, when a class extends another class, it inherits all methods from the base class. If the derived class defines a method with the same name as a method in the base class, it overrides that method. However, TypeScript enforces strict compatibility rules for method overriding: the overriding method must be assignable to the base method.
How do I fix "Method 'x' in type 'X' cannot be assigned to the same method in base t"?
This TypeScript error occurs when a derived class attempts to override a method from its base class with an incompatible signature. The method in the derived class must be assignable to the base class method, meaning it should have compatible parameter types and return type. Fixing this involves ensuring method signatures match or using appropriate type annotations.
What causes "Method 'x' in type 'X' cannot be assigned to the same method in base t"?
Changing the return type of an overridden method to an incompatible type Adding required parameters to an overridden method that the base method does not have Changing parameter types to incompatible types (e.g., string to number)
Is the "Method 'x' in type 'X' cannot be assigned to the same method in base t" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading