Skip to content

Typescript Error: EventEmitter is not a constructor function type. #46

@trival

Description

@trival

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:

declare class export_default extends EventEmitter<EventTypes> {
    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 geckosio/geckos.io#22 or axios/axios#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions