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
TypeScript allows to return this from instance methods, which is to say the least, is great. It would be even better if it allowed doing the same with static methods. The rationale is consistency and feature.
Line public static construct():this below will report error TS2526: A 'this' type is available only in a non-static member of a class or interface., the line below uses this inside static method to create a new instance of the class, the line below that also uses this to return static property. The error message is misleading, this can be and should be used inside static methods whenever appropriate.
I'd like to inherit Foo and use construct on child classes, the only way I can do this by specifying Foo as return type, however, this will require to cast the result to Bar and Baz whenever called from those classes – inconvenient and inconsistent with instance method behaviour.
This seems to be common sense, since this already done for instance methods, shouldn't be much pain doing this for static methods either? What are your thoughts?
The text was updated successfully, but these errors were encountered:
TypeScript allows to return
this
from instance methods, which is to say the least, is great. It would be even better if it allowed doing the same with static methods. The rationale is consistency and feature.Line
public static construct():this
below will reporterror TS2526: A 'this' type is available only in a non-static member of a class or interface.
, the line below usesthis
inside static method to create a new instance of the class, the line below that also usesthis
to return static property. The error message is misleading,this
can be and should be used inside static methods whenever appropriate.I'd like to inherit
Foo
and useconstruct
on child classes, the only way I can do this by specifyingFoo
as return type, however, this will require to cast the result toBar
andBaz
whenever called from those classes – inconvenient and inconsistent with instance method behaviour.This seems to be common sense, since this already done for instance methods, shouldn't be much pain doing this for static methods either? What are your thoughts?
The text was updated successfully, but these errors were encountered: