[nedb] Nedb class should extend EventEmitter (#31669)

This commit is contained in:
Dimitri Benin
2018-12-31 09:02:12 -08:00
committed by Wesley Wigham
parent 9e661f99a8
commit e8cd4c9394
2 changed files with 27 additions and 1 deletions
+16 -1
View File
@@ -5,10 +5,14 @@
// Alejandro Fernandez Haro <https://github.com/afharo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { EventEmitter } from 'events';
export = Nedb;
export as namespace Nedb;
declare class Nedb {
declare class Nedb extends EventEmitter {
constructor(pathOrOptions?: string | Nedb.DataStoreOptions);
persistence: Nedb.Persistence;
@@ -153,6 +157,17 @@ declare class Nedb {
*/
remove(query: any, options: Nedb.RemoveOptions, cb?: (err: Error, n: number) => void): void;
remove(query: any, cb?: (err: Error, n: number) => void): void;
addListener(event: 'compaction.done', listener: () => void): this;
on(event: 'compaction.done', listener: () => void): this;
once(event: 'compaction.done', listener: () => void): this;
prependListener(event: 'compaction.done', listener: () => void): this;
prependOnceListener(event: 'compaction.done', listener: () => void): this;
removeListener(event: 'compaction.done', listener: () => void): this;
off(event: 'compaction.done', listener: () => void): this;
listeners(event: 'compaction.done'): Array<() => void>;
rawListeners(event: 'compaction.done'): Array<() => void>;
listenerCount(type: 'compaction.done'): number;
}
declare namespace Nedb {
+11
View File
@@ -514,3 +514,14 @@ db.insert({ somefield: 'nedb' }, (err: Error) => {
// Remove index on field somefield
db.removeIndex('somefield', (err: Error) => {
});
db.addListener("compaction.done", () => {});
db.on("compaction.done", () => {});
db.once("compaction.done", () => {});
db.prependListener("compaction.done", () => {});
db.prependOnceListener("compaction.done", () => {});
db.removeListener("compaction.done", () => {});
db.off("compaction.done", () => {});
db.listeners("compaction.done"); // $ExpectType (() => void)[]
db.rawListeners("compaction.done"); // $ExpectType (() => void)[]
db.listenerCount("compaction.done"); // $ExpectType number