我有一個擴展EventEmmiter
類的類。找不到TypeScript聲明類
我想智能感知顯示,你可以聽不同的事件,並幫助汽車完成它們,所以我想出了這個:
//Imports from index.ts
import {
CommandContext,
CommandErrorContext,
CommandHandler
} from '../../';
import { EventEmitter } from 'events';
export class CommandHandler extends CommandHandlerEvents {
constructor() {
super();
}
}
export declare class CommandHandlerEvents extends EventEmitter {
on(event: string, listener: Function): this;
on(event: 'failure', listener: (handler: CommandHandler, context: CommandErrorContext) => void): this;
on(event: 'success', listener: (handler: CommandHandler, context: CommandContext) => void): this;
once(event: string, listener: Function): this;
once(event: 'failure', listener: (handler: CommandHandler, context: CommandErrorContext) => void): this;
once(event: 'success', listener: (handler: CommandHandler, context: CommandContext) => void): this;
emit(event: string, args: any[]): boolean;
emit(event: 'failure', args: [CommandHandler, CommandErrorContext]): boolean;
emit(event: 'success', args: [CommandHandler, CommandContext]): boolean;
}
上面的代碼不正是我想要它做的,但是當我創建CommandHandler
類的實例,它拋出這個錯誤:
Uncaught ReferenceError: CommandHandlerEvents is not defined
我看了一下使用接口做同樣的事情的人,但是當我改變CommandHandlerEvents
從declare class
到interface
這些建議不再顯示在IntelliSense上。理想的結果的
例子:image
是否在任何地方聲明瞭「EventEmitter」或「CommandErrorContext」或「CommandContext」? – recursive
@recursive是的,我會更新代碼 – DusterTheFirst