You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript
I think that is useful to access to static members :
from instances
from sub classes
Below an example:
class A {
protected static type: string;
public log(): string {
console.log(this.type);
}
}
class B extends A {
protected static type: string = 'C';
}
class C extends A {
protected static type: string = 'C';
}
b = new B();
b.log(); // => 'B'
c = new C();
c.log(); // => 'C'
By default the constructor property of an instance is of type Function, but you can specialize it in a class by manually declaring it. Once you do that you can access the statics through this.constructor.xxx, and you'll get the properties of the constructor object that actually created the instance (i.e. the derived constructor object).
Reacted by Srinath Sankar, Piotr Witek, Romain Lepert and Zhongyang Wang
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript
Activity
ahejlsberg commentedon Dec 9, 2015
We can't do it the way you suggest since
this.typeis used to access an instance property namedtype, not a static property.However, your example works if you write it as follows:
By default the
constructorproperty of an instance is of typeFunction, but you can specialize it in a class by manually declaring it. Once you do that you can access the statics throughthis.constructor.xxx, and you'll get the properties of the constructor object that actually created the instance (i.e. the derived constructor object).