Extend a class in a third-party definition file

I am providing a typescript definition file for a non-ts library I wrote. My library extends EventEmitter2

as a "native" event system, so I'm trying to figure out how to define it:

/// <reference types="eventemitter2" />

declare module "my-module" {
  class MyClass extends EventEmitter2 {
    // ...
  }
}

      

... which doesn't work. EventEmitter2 provides a file d.ts

, so it should be available, but I get the following message:

Cannot find name 'EventEmitter2'

I am not working with enough to know where I am going wrong. I tried reading the docs / looking for examples, but nothing seems to be the problem.

+3


source to share


1 answer


Instead of using the triple-slash directive, you can import 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 file .d.ts

is in the module itself and is not under node_modules/@types

.

+1


source







All Articles