elemaudio / elemaudio/elementary

Typescript Error: EventEmitter is not a constructor function type.

Open
#46 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
513
Forks
46
PR merge metrics
No merged PRs in 30d

Description

After upgrading to latest version of elementary and typescript, I am getting the error in the title from typescript.

The error occurs in line 76 of `node_modules/@elemaudio/core/dist/index.d.ts` that says:
```typescript
declare class export_default extends EventEmitter {
constructor();
}
```

I therefore can't use any EventEmitter functions on the WebRenderer object without typescript complaining.

My project uses `"type": "module"` in package.json, and `"moduleResolution": "Node16"` in tsconfig.json (because of some other typescript errors from other libraries).

After looking at similar issues on Github, like https://github.com/geckosio/geckos.io/issues/22 or https://github.com/axios/axios/issues/6225, it seems that changing

```import EventEmitter from 'eventemitter3';```
to
```import { EventEmitter } from 'eventemitter3';```

should fix this error. It at least fixed the error when I changed that code in the published `node_modules/@elemaudio/core/dist/index.d.ts`.

If that would work for you and cause no other troubles, maybe it is worth to use the direct import syntax of EventEmitter.

Actually running the code using vite works by the way, it is only typescript complaining.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the TypeScript error with the generated declaration in node_modules/@elemaudio/core/dist/index.d.ts under moduleResolution Node16. Trace that declaration back to the package source, then verify that WebRenderer exposes its EventEmitter functions to TypeScript while the existing Vite runtime continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
developer-experience, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.