bgenc.net/content/posts/2022.04.18.javascript-typee...

841 B

title date draft toc images tags
JavaScript error "Super Expression must either be null or a function" 2022-04-18T04:05:40-04:00 true false
dev
javascript
typescript

I just got this error when working on some TypeScript code.

Uncaught TypeError: Super Expression must either be null or a function

The line for the error pointed to the constructor of a class. What's happening? Circular dependencies it turns out.

// in foo.ts
class Foo {
  foo() {
    new Bar().doSomething();
  }
}

// in bar.ts
class Bar extends Foo {
  // ...
}

It's obvious when boiled down like this, but it's something you'll want to make sure to avoid. I solved this issue by making Bar not extend Foo. It added little to no duplicated code for me in this case, so just separating the classes was easy enough.