I am using typescript and I am getting error TypeError: Class extends value undefined is not a constructor or null

453 Views Asked by At

I am building a microservice app which has a nats streaming setup, but when I create a instance of my listener class I get the error

TypeError: Class extends value undefined is not a constructor or null
[company]     at Object.<anonymous> (/app/src/events/listeners/tenant-created-listener.ts:8:44)
[company]     at Module._compile (node:internal/modules/cjs/loader:1233:14)
[company]     at Module._compile (/app/node_modules/source-map-support/source-map-support.js:568:25)
[company]     at Module.m._compile (/tmp/ts-node-dev-hook-9408356301483605.js:69:33)
[company]     at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
[company]     at require.extensions..jsx.require.extensions..js (/tmp/ts-node-dev-hook-9408356301483605.js:114:20)
[company]     at require.extensions.<computed> (/tmp/ts-node-dev-hook-9408356301483605.js:71:20)
[company]     at Object.nodeDevHook [as .ts] (/app/node_modules/ts-node-dev/lib/hook.js:63:13)
[company]     at Module.load (node:internal/modules/cjs/loader:1091:32)
[company]     at Function.Module._load (node:internal/modules/cjs/loader:938:12)
[company] [ERROR] 10:38:48 TypeError: Class extends value undefined is not a constructor or null

my files are

  • The issue is when I creating this instance The issue is when I creating this instance

  • The issue points to here The issue points to here

  • This is the listener class which I am extending This is the listener class which I am extending

1

There are 1 best solutions below

1
Matthieu Riegler On BEST ANSWER

When you use declare in typescript, you're telling the compiler to not generate the class.

So at runtime when you extends your abstract class, the parent class listener is not defined.

Just remove your declare and you'll be fine:

abstract class listener<T> { ... }