Typeerror: super expression must either be null or a function

Are you dealing with a “typeerror: super expression must either be null or a function” error message right now?

And you’re having a hard time fixing it?

If yes, this article is indeed for you. Want to know why?

This is because…

In this article, we are going to show how to troubleshoot this “super expression must either be null or a function” error message.

So, keep on reading.

What is “typeerror: super expression must either be null or a function”?

The “typeerror super expression must either be null or a function” is an error message that occurs in JavaScript when the “super” keyword is used incorrectly.

In addition to that, it indicates that the usage of “super” is not valid and it must either be set to null or used as a function call to refer to the parent class constructor.

Why does this error occur?

Here are the most common causes of the “super expression must either be null or a function” error.

  • Incorrect usage of “super” keyword
  • Not extending a parent class
  • Typo or misspelling

On the other hand, in object-oriented programming languages like Python or JavaScript, “super” is used to refer to the parent class or superclass from within a subclass.

However, there are certain rules that need to be followed:

→ “super” must be used within the constructor of the subclass.

→ If “super” is used with parentheses, it should be followed by arguments (if the parent class constructor requires them).

→ If “super” is used without parentheses, it refers to the parent class constructor without passing any arguments.

→ “Super” can also be used to call methods of the parent class from within the subclass.

How to fix “typeerror: super expression must either be null or a function”

Here are the different solutions you may use to fix the “super expression must either be null or a function” error immediately:

1. Use “super” keyword correctly within the constructor of the subclass

Make sure that you’re using the “super” keyword correctly within the constructor of the subclass.

The “super” should only be used within the constructor, and it should be followed by parentheses if you want to call the parent class constructor with arguments.

Example code:

class ParentClass {
  constructor(arg1) {
    // Parent class constructor code here
  }
}

class ChildClass extends ParentClass {
  constructor(arg1, arg2) {
    super(arg1); // Correctly calling parent class constructor with arg1
    this.property = arg2; // Initializing subclass's own property
  }
}

2. Check for any other incorrect usage of “super” in your subclass methods.

The “super” should only be used to call the parent class constructor or methods, and it should be used in a valid manner within the constructor or methods of the subclass.

Example code:

class ParentClass {
  someMethod() {
    // Parent class method code here
  }
}

class ChildClass extends ParentClass {
  someMethod() {
    super.someMethod(); // Correctly calling parent class method
    // Subclass method code here
  }
}

3. Ensure passing the required arguments to “super()”

Ensure that you are passing the required arguments to “super()” if the parent class constructor requires it.

When the parent class constructor has parameters, you need to pass those parameters as arguments to “super()” in the subclass constructor.

Example code:

class ParentClass {
  constructor(arg1) {
    // Parent class constructor code here
  }
}

class ChildClass extends ParentClass {
  constructor(arg1, arg2) {
    super(arg1); // Correctly calling parent class constructor with arg1
    this.property = arg2; // Initializing subclass's own property
  }
}

Note: If the above solutions do not resolve the error try to double-check for any typos or misspelling in the usage of the “super” keyword or the parent class name.

Ensure they are correctly spelled and referenced in the code to avoid error.

Conclusion

By executing the different solutions that this article has already given and making sure that you’re using the “super” keyword correctly, passing required arguments, and using it only within valid contexts.

You can definitely fix the “typeerror: super expression must either be null or a function” error in JavaScript.

We are hoping that this article provides you with sufficient solutions.

You could also check out other “typeerror” articles that may help you in the future if you encounter them.

Thank you very much for reading to the end of this article.

Python TypeError debugging checklist

  • Read the full traceback. The bottom line is the error type + message. The line above shows the exact code that triggered it.
  • Print types. Insert print(type(x), type(y)) before the error line to see what Python actually has.
  • Use isinstance. Guard code with if isinstance(x, expected_type):.
  • Type hints + mypy. Adding x: int lets mypy catch mismatches before you run the code.
  • Break into a debugger. Insert breakpoint() before the failing line and inspect variables live.

Common root causes across all TypeError variants

  • Silent None returns. A function that should have returned a value returned None instead.
  • Mixing types across function boundaries. Legacy code passing str where int is expected (or vice versa).
  • Shadowed builtins. Local variable named list, dict, set overriding the built-in.
  • Optional[T] not handled. Callers not accounting for the None case.
  • Third-party library API drift. New version renamed a kwarg or changed a return type.

Modern tooling to prevent TypeError

  • Type hints (PEP 484+). Optional[X], Union[X,Y], List[T] make expected types explicit.
  • mypy or Pyright. Runs your codebase through a type checker before you run it.
  • Ruff. Fast linter that catches many TypeError-adjacent bugs.
  • pydantic v2. Runtime validation with the same syntax as static types.
  • pytest fixtures. Test each function with edge-case inputs to catch TypeError paths early.

Frequently Asked Questions

What is Python TypeError and what causes it?

TypeError is raised when an operation is applied to an object of the wrong type. Common patterns: calling a non-callable object, adding incompatible types (str + int), passing the wrong number of arguments, or accessing attributes on a NoneType. Each TypeError message names the operation and expected vs actual types, the fix is almost always to convert types explicitly (int(), str()) or fix the wrong variable assignment.

How do I quickly debug a Python TypeError?

Three steps: (1) Read the full error message, it names the exact operation and types involved. (2) Print the type of every variable in that line: print(type(var1), type(var2)). (3) Check what the function expected vs what you passed. Most TypeError fixes are 1-line type casts or fixing a variable that became None unexpectedly.

Should I catch TypeError or let it propagate?

For internal code, let TypeError propagate, it’s almost always a real bug (wrong type passed). For boundary code (parsing user input, third-party API responses), catch TypeError + ValueError together: try: parsed = int(value) except (TypeError, ValueError): parsed = 0. Catching internal TypeErrors hides bugs.

How do I prevent TypeError in production?

Three patterns: (1) Use type hints (def add(a: int, b: int) -> int) and check with mypy / pyright in CI. (2) Validate inputs at boundaries (Pydantic for FastAPI, DRF serializers for Django). (3) Default values that match expected types (return 0 not None for numeric functions). Static typing catches 80% of TypeErrors before runtime.

Where can I find more TypeError fixes?

Browse the TypeError reference hub for 220+ specific TypeError fixes. For broader Python debugging, see the Python Tutorial hub. For related error types, see ValueError and AttributeError guides.

Caren Bautista


Technical Writer at PIES IT Solution

Responsible for crafting clear, well-structured, and beginner-friendly content across the platform. Handles the writing, proofreading, and editorial review of tutorials, guides, and documentation to ensure every article is accurate, readable, and easy to follow.

Expertise: Technical Writing · Content Creation · Documentation · Editorial Writing · JavaScript · TypeScript · Python · Python Errors · HTTP Errors · MS Excel
 · View all posts by Caren Bautista →