클래스와 같은 타입 스크립트 선언 파일 안의 인터페이스 나 변수를 클래스에서 확장 할 수있는 방법이 있습니까? 이처럼Typescript의 선언 인터페이스에서 클래스 확장하기
:
declare module "tedious" {
import events = module('events');
export class Request extends event.EventEmitter {
constructor (sql: string, callback: Function);
addParameter(name: string, type: any, value: string):any;
addOutputParameter(name: string, type: any): any;
sql:string;
callback: Function;
};
}
는 지금은이 같은 EventEmitter 인터페이스를 재정의하고 내 자신의 EventEmitter 선언을 사용해야합니다.
import events = module('events');
class EventEmitter implements events.NodeEventEmitter{
addListener(event: string, listener: Function);
on(event: string, listener: Function): any;
once(event: string, listener: Function): void;
removeListener(event: string, listener: Function): void;
removeAllListener(event: string): void;
setMaxListeners(n: number): void;
listeners(event: string): { Function; }[];
emit(event: string, arg1?: any, arg2?: any): void;
}
export class Request extends EventEmitter {
constructor (sql: string, callback: Function);
addParameter(name: string, type: any, value: string):any;
addOutputParameter(name: string, type: any): any;
sql:string;
callback: Function;
};
그리고 내 타이프 라이터 파일
import tedious = module('tedious');
class Request extends tedious.Request {
private _myVar:string;
constructor(sql: string, callback: Function){
super(sql, callback);
}
}
하지만 그때 나는 모든 EventEmitter 구현을 놓치고 Typescript는 누락 된 속성 오류를 발생시킬 것입니다. 이것이 내가 처음으로 NodeJS EventEmmiter 클래스를 재정의 한 이유입니다. – Manuel