Open samchon opened 8 years ago
Related to #8606
If you only want to call super constructor and nothing else, just leave out the constructor from the derived class. Derived classes inherit the constructor of the base class if they don't have a constructor of their own.
class A<T> {
public arg: T;
constructor();
constructor(arg: T);
constructor(...args: any[]) {
if (args.length === 1) {
this.arg = args[0];
}
else {
this.arg = null;
}
}
}
class B<T> extends A<T> {
}
console.log(new B<string>("x").arg); // "x"
console.log(new B<string>().arg); // null
I wounder if we could get this as part of https://github.com/Microsoft/TypeScript/issues/2000, if were to specify that an overridden implementation inherits all overloads from the base.
Problem
Outline
When I make a new sub-class from a parent-class who has multiple overloaded constructors (or some methods), I've to re-write the definition (header) of each function and re-write branch-condition again. It's very annoying and tiresome work for me.
With an example
https://github.com/samchon/stl/blob/master/ts/src/std/TreeMap.ts#L72-L177
In the link, you can see the TreeMap class inherited from base.UniqueMap. Of course, you also can see that the constructors and branch-condition codes have to be re-written.
Those idiot codes are repeated in every sub-classes in my fucking project.
Solution
Suggest: using statement
Those're very annoying and inefficient job for development. So I want to suggest a notation can reduce such in-efficient works.
In C++, fetching all overloaded methods from parent can be implemented by just a line. With using statement.
using Parent::methodName;
If the using statement is adopted in TypeScript, codes will be much precise like below. Isn't it much precise than codes of the top?
I'm waiting for your opinion and eagerly looking forward to the enhancement.