javascript error

This commit is contained in:
Kaan Barmore-Genç 2022-04-18 04:13:26 -04:00
parent 396056db87
commit 516ad7a530
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
---
title: "JavaScript error \"Super Expression must either be null or a function\""
date: 2022-04-18T04:05:40-04:00
draft: true
toc: false
images:
tags:
- 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.
```ts
// 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.