How to declare a subclass of EventEmitter?

Viewed 54

I am writing type definitions for JS code in types.d.ts and I want to declare a class that subclasses EventEmitter, but it won't let me:

type EventEmitter = import('events').EventEmitter

// 'EventEmitter' only refers to a type, but is being used as a value here.ts(2693)
declare class Foo extends EventEmitter {}

How can I do this?

UPDATE: As a workaround, I copied the nodejs.eventemitter interface definition into my types.d.ts, and changed interface to declare class, and it works. Is this a bug in the NodeJS typing?

1 Answers

[Edit] Changing the import I don't get an error

import type {EventEmitter} from 'events'

declare class Foo extends EventEmitter {}

Playground

Related