scottcorgan / tiny-emitter

A tiny (less than 1k) event emitter library
MIT License
935 stars 67 forks source link

Emitter expression is not constructable #47

Open gustavojb92 opened 1 year ago

gustavojb92 commented 1 year ago

I'm a starter and I hope you beg my pardon cuz maybe I'm looking a little stupid for you, but, I can't solve that problem. I created a util called bus, and I am trying to use the Emitter with TS :

import Emitter from "tiny-emitter";

export default new Emitter();

but I received that error:

This expression is not constructable.
  Type 'typeof import("C:/projeto Controle Financeiro/wa-controle-financeiro/node_modules/tiny-emitter/index")' has no construct signatures.

I hope you can help me.

ameerjahanap commented 1 year ago

The error occurred because the class is exported as named export whereas you imported it as a default import. So instead of import Emitter from "tiny-emitter"; , you should import it as import { TinyEmitter } from "tiny-emitter"; according to the d.ts file.

Edit: The d.ts file from the npm registry is incomplete compared to the file on github. Hence the error. Otherwise import Emitter from "tiny-emitter"; should work!