IssueRaiser

T.constructor should be of type T

Given ``` typescript 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: ``` typescript 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: ``` typescript 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.

Posted by LPGhatguy on Jul 13, 2015, 5:43 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.5,500 issues0 comments

github (Other)

T.constructor should be of type T

LPGhatguyJul 13, 2015, 5:43 PM

Given ``` typescript 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: ``` typescript 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: ``` typescript 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.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue