Reputation: 37481
I provide a typescript definition file for a non-ts library I've written. My library extends EventEmitter2
as a "native" event system so I'm trying to determine how to define that:
/// <reference types="eventemitter2" />
declare module "my-module" {
class MyClass extends EventEmitter2 {
// ...
}
}
... which doesn't work. EventEmitter2 provides a d.ts
file so it should be available, but the error I get is:
Cannot find name 'EventEmitter2'
I don't work with ts enough to know where I'm going wrong. I've tried reading docs/looking for examples but nothing seems to address this type of issue.
Upvotes: 3
Views: 856
Reputation: 58430
Rather than using a triple-slash directive, you can import the type declarations from eventemitter2
:
import { EventEmitter2 } from 'eventemitter2';
declare module "my-module" {
class MyClass extends EventEmitter2 {
// ...
}
}
The triple-slash directive does not work because the .d.ts
file is in the module itself and is not under node_modules/@types
.
Upvotes: 2