Typescript: Overloading event handlers
up vote
0
down vote
favorite
I am trying to extend an existing interface to add additional event handlers. The interface I am extending already has several event handlers defined.
Here is the base interface:
export interface Emitter
on(event: 'connect', listener: (err: Error) => void ):this;
on(event: 'end', listener: () => void ):this;
Here is also the base class:
export class Emitter extends events.EventEmitter
Here is my interface:
export interface EmitterExtended extends Emitter
on(event: 'status', listener: (status: ConnectionStatus) => void ):this;
status?: ConnectionStatus;
And here is the error typescript gives:
Interface 'EmitterExtended' incorrectly extends interface 'Emitter'.
Types of property 'on' are incompatible.
typescript events interface
add a comment |
up vote
0
down vote
favorite
I am trying to extend an existing interface to add additional event handlers. The interface I am extending already has several event handlers defined.
Here is the base interface:
export interface Emitter
on(event: 'connect', listener: (err: Error) => void ):this;
on(event: 'end', listener: () => void ):this;
Here is also the base class:
export class Emitter extends events.EventEmitter
Here is my interface:
export interface EmitterExtended extends Emitter
on(event: 'status', listener: (status: ConnectionStatus) => void ):this;
status?: ConnectionStatus;
And here is the error typescript gives:
Interface 'EmitterExtended' incorrectly extends interface 'Emitter'.
Types of property 'on' are incompatible.
typescript events interface
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to extend an existing interface to add additional event handlers. The interface I am extending already has several event handlers defined.
Here is the base interface:
export interface Emitter
on(event: 'connect', listener: (err: Error) => void ):this;
on(event: 'end', listener: () => void ):this;
Here is also the base class:
export class Emitter extends events.EventEmitter
Here is my interface:
export interface EmitterExtended extends Emitter
on(event: 'status', listener: (status: ConnectionStatus) => void ):this;
status?: ConnectionStatus;
And here is the error typescript gives:
Interface 'EmitterExtended' incorrectly extends interface 'Emitter'.
Types of property 'on' are incompatible.
typescript events interface
I am trying to extend an existing interface to add additional event handlers. The interface I am extending already has several event handlers defined.
Here is the base interface:
export interface Emitter
on(event: 'connect', listener: (err: Error) => void ):this;
on(event: 'end', listener: () => void ):this;
Here is also the base class:
export class Emitter extends events.EventEmitter
Here is my interface:
export interface EmitterExtended extends Emitter
on(event: 'status', listener: (status: ConnectionStatus) => void ):this;
status?: ConnectionStatus;
And here is the error typescript gives:
Interface 'EmitterExtended' incorrectly extends interface 'Emitter'.
Types of property 'on' are incompatible.
typescript events interface
typescript events interface
edited Nov 9 at 13:54
asked Nov 8 at 23:33
AmunRa
103
103
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Found the solution here
By declaring a module with the same name as the imported module, you can augment existing declarations
import Observable from "./observable";
declare module "./observable"
interface Observable<T>
map<U>(f: (x: T) => U): Observable<U>;
Observable.prototype.map = function (f)
// ... another exercise for the reader
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Found the solution here
By declaring a module with the same name as the imported module, you can augment existing declarations
import Observable from "./observable";
declare module "./observable"
interface Observable<T>
map<U>(f: (x: T) => U): Observable<U>;
Observable.prototype.map = function (f)
// ... another exercise for the reader
add a comment |
up vote
0
down vote
accepted
Found the solution here
By declaring a module with the same name as the imported module, you can augment existing declarations
import Observable from "./observable";
declare module "./observable"
interface Observable<T>
map<U>(f: (x: T) => U): Observable<U>;
Observable.prototype.map = function (f)
// ... another exercise for the reader
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Found the solution here
By declaring a module with the same name as the imported module, you can augment existing declarations
import Observable from "./observable";
declare module "./observable"
interface Observable<T>
map<U>(f: (x: T) => U): Observable<U>;
Observable.prototype.map = function (f)
// ... another exercise for the reader
Found the solution here
By declaring a module with the same name as the imported module, you can augment existing declarations
import Observable from "./observable";
declare module "./observable"
interface Observable<T>
map<U>(f: (x: T) => U): Observable<U>;
Observable.prototype.map = function (f)
// ... another exercise for the reader
answered Nov 11 at 0:32
AmunRa
103
103
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217733%2ftypescript-overloading-event-handlers%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown