Definitelytyped: [@types/node] EventEmitter as namespace in 3.5+ causes tsc errors

Created on 6 Feb 2020  路  8Comments  路  Source: DefinitelyTyped/DefinitelyTyped

If you know how to fix the issue, make a pull request instead.

  • [x] I tried using the @types/node package and had problems.
  • [x] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [x] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [x] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @Flarna

I just added @types/node to my project (I'm using tsc 3.7.4), and now I get typescript errors in other seemingly unrelated dependencies when building.

% tsc --noEmit
../../node_modules/@types/pino/index.d.ts:371:34 - error TS2709: Cannot use namespace 'EventEmitter' as a type.

371     interface BaseLogger extends EventEmitter {
                                     ~~~~~~~~~~~~

../../node_modules/jest-haste-map/build/index.d.ts:125:32 - error TS2507: Type 'typeof EventEmitter' is not a constructor function type.

125 declare class HasteMap extends EventEmitter {
                                   ~~~~~~~~~~~~

It seems to be related to this refactor by @Flarna :
https://github.com/DefinitelyTyped/DefinitelyTyped/commit/19826ba267c2203e61d28b87f56ca28eac23a994#diff-7d7d86e4d89d5a8d8e623c8873828549
in which EventEmitter is created as a namespace, probably confusing these other modules.

Reverting to 13.1 causes the errors to go away.

Most helpful comment

I'm seeing this as well when importing via import EventEmitter from 'events'; rather than import {EventEmitter} from 'events';. Using the default export worked prior to the commit @garyo referenced.

All 8 comments

CC @SimonSchick

Can you please provide a minimum repro?
I don't see those issues.

I'll see what I can do; my project is pretty large. Could you try it with @types/pino?

I have the DT repo cloned locally and checked all packages that contain import { EventEmitter } from 'events'; I do not see any issues.

I'm seeing this as well when importing via import EventEmitter from 'events'; rather than import {EventEmitter} from 'events';. Using the default export worked prior to the commit @garyo referenced.

Recently I've got the same issue on one of the environments. @garyo, what exactly have you reverted to 13.1?

In that commit I reverted @types/node to 13.1 and @types/pino to ^5.15.4. That made it start working.

Was this page helpful?
0 / 5 - 0 ratings