Open
Description
openedon Jul 13, 2015
Given
class Example {
}
The current type of Example.constructor
is Function
, but I feel that it should be typeof Example
instead. The use case for this is as follows:
I'd like to reference the current value of an overridden static property on the current class.
In TypeScript v1.5-beta, doing this requires:
class Example {
static someProperty = "Hello, world!";
constructor() {
// Output overloaded value of someProperty, if it is overloaded.
console.log(
(<typeof Example>this.constructor).someProperty
);
}
}
class SubExample {
static someProperty = "Overloaded! Hello world!";
someMethod() {
console.log(
(<typeof SubExample>this.constructor).someProperty
);
}
}
After this proposal, the above block could be shortened to:
class Example {
static someProperty = "Hello, world!";
constructor() {
// Output overloaded value of someProperty, if it is overloaded.
console.log(
this.constructor.someProperty
);
}
}
class SubExample {
static someProperty = "Overloaded! Hello world!";
someMethod() {
console.log(
this.constructor.someProperty
);
}
}
This removes a cast to the current class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment