ai/nanoevents

Incorrect type declarations

jakub791 opened this issue · 4 comments

The problem

In index.d.ts Emitter is declared to be a class. That's incorrect.

import { Emitter } from "nanoevents";

const emitter = new Emitter<{
    tick: () => void;
}>();

emitter.on("tick", () => console.log("tick"));
emitter.emit("tick");

At runtime the above code snippet throws an error Import named 'Emitter' not found in module '/home/jakub/server/node_modules/nanoevents/index.js'. because nanoevents dosen't export a value named Emitter. Even thought type definitions imply it should, because a class should to exist at runtime.

Solution

Emitter should be declared as a type alias/interface, not a class so that typescript dosen't allow you to use it where a value is expected.

ai commented

Good idea. Do you want to send PR to save your name in the project history?

Sure.

Done. #67

ai commented

Thanks. Released in 8.0.