Typescript method overloading in subclass -


here's example:

class {   func(): void {} }  class b extends {   func(a: number, b: string): void {} } 

class b gives error saying func() implemented incorrectly.

ultimately, i'm trying make work:

var b: b; b.func(0, '');     // func overloaded b b.func();          // func inherited 

is possible in typescript?

update: fixed code, accidentally used function properties instead of methods.

when using arrow functions don't class methods members of type/value of function.
difference being while methods added prototype, arrow functions added instance in constrctor:

class myclass {     method() {}     funct = () => {} } 

compiles to:

var myclass = (function () {     function myclass() {         this.func = function () { };     }     myclass.prototype.method = function () { };     return myclass; }()); 

that's fine of course, if that's want.
main problem overloading , calling parent method aren't simple.

in case, overloading:

class {     func(): void {} }  class b extends {     func(): void; // parent signature     func(a: number, b: string): void; // new signature     func(): void {         if (arguments.length === 0) {             super.func();         } else {             // actual implementation         }     } } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -