Add @types declaration file.
thisis-Shitanshu opened this issue · comments
Hello! your module is being used a lot in typescript application and since your module has no type declaration. I have found a lot of users have to declare the declaration separately.
To add the type declaration for your npm module, you can simply add the following code to a file with '.d.ts' extension in your root (preferably: index.d.ts) and publish it. If you follow this, you won't have to convert your module to typescript.
declare module "promise-events" {
class EventEmitter {
emit<T = void>(event: string | symbol, ...args: any[]): Promise<T>;
on<T = void>(event: string | symbol, handler: (...args: any[]) => Promise<T>): void;
}
}
You can know more about it from here.
I have honestly never used TypeScript neither really care for it. But I will try to add this file. Feel free to comment once it's done.
@yanickrochon the newly added TypeScript definition seems to have a bug that's breaking the compilation of upstream applications, see probot/probot#1163
One issue seems to be that function
should be Function
; but correcting this I still get the error:
node_modules/probot/lib/application.d.ts:5:10 - error TS2614: Module '"promise-events"' has no exported member 'EventEmitter'. Did you mean to use 'import EventEmitter from "promise-events"' instead?
5 import { EventEmitter } from 'promise-events';
As I stated previously, I do not personally use TypeScript and only provided the file out of courtesy. I will remove it, and if someone really want it, then submit a PR. :)
@yanickrochon appreciate it, one thought, what we do for yargs is rely on a community contributed TypeScript definition available on DefinitelyTyped. A user of promise-events
would then simply install @types/promise-events
.
The value here is that you decouple your library from the TypeScript definition, if you yourself aren't want to maintain it.
Hi @bcoe I have absolutely no objection to that. This is why I publish modules, because of the open source community :)