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
I was just about to comment on asking for something like this, it's not yet reached a pain point in the project I'm working on (due to the size) but might soon.
I simply want to make sure I don't forget to override an abstract method in a base (base...) class and that's it. The feature can be implemented as rigidly as you want as long as it helps me code better - meaning I really don't care about other subtleties as mentioned in #6 though I'm aware some are important to clarify before implementation begins as it clashes with some of the JS oddities.
TypeScript is shaping up to be a really great language (seeing what you've started with - JavaScript - can't be considered great unless you're heavily drunk 😉 )
Ryan Cavanaugh (@RyanCavanaugh) I have another question about abstract classes. I wonder how I define a function that accepts a derived abstract class that is not abstract and the function should also "new" it.
Ryan Cavanaugh (@RyanCavanaugh) does it makes sense with optional abstract methods? I want to define an abstract class with some abstract methods on it. But I want a derived class doesn't need to implement all of the methods.
Since you allow optional on interfaces I think it makes very much sense to allow it on abstract methods as well.
I want to have one abstract class and two child classes.
Each child should have some class-dependent value (not instance-dependent).
I want to access this value without creating an instance of class.
I want to access this value when I don't know which specific child-class I'm accessing (examples below).
So I want to be sure, that every child of an abstract class has this static method.
abstractclassAbs{/*public static getSomeValue() { return null; }*/}classChild1extendsAbs{publicstaticgetSomeValue(){return'Some value of class Child1';}}classChild2extendsAbs{publicstaticgetSomeValue(){return'Some value of class Child2';}}classFactory{publicstaticgetClasses(): (typeofAbs)[]{return[Child1,Child2];}}varclasses=Factory.getClasses();for(varindexinclasses){if(classes.hasOwnProperty(index)){classes[index].getSomeValue();}}
So there is two ways to be sure that classes[index].getSomeValue();will not cause an error:
Implement the same method in abstract class (commented out in example above). De facto this method will be a kind of stub.
Check an availability of getSomeValue method every time before call, that not seems to be good idea.
Declaring abstract static method in abstract class will resolve the problem.
Reacted by Yaroslav Admin, Kaleb Hornsby, Levente Morva, Maciej Bukowski, Jordan Amos, cailenmusselman, Jon Con, Roberto Asiel Guevara Castañeda, Rémi Chanaud, Alex Block and 2 more
Unless there's another way I can go about writing a simple Serializable interface like this?
Reacted by Jamie Patel, Alexander, Kaleb Hornsby, Preston Pham, n00dl3, Ian Ker-Seymer, Julián Díaz, Maciej Bukowski, Joshua Gross, Jesse Zhang and 31 more
Anton Dyshkant (@vyshkant) @Aarilight did your use cases go away, or are they still valid? If they are, then we should submit an issue as Ryan Cavanaugh (@RyanCavanaugh) suggests. If one of you guys starts the issue, I may eventually have a use case to add to it.
Activity
ddotlic commentedon May 1, 2015
I was just about to comment on asking for something like this, it's not yet reached a pain point in the project I'm working on (due to the size) but might soon.
I simply want to make sure I don't forget to override an abstract method in a base (base...) class and that's it. The feature can be implemented as rigidly as you want as long as it helps me code better - meaning I really don't care about other subtleties as mentioned in #6 though I'm aware some are important to clarify before implementation begins as it clashes with some of the JS oddities.
TypeScript is shaping up to be a really great language (seeing what you've started with - JavaScript - can't be considered great unless you're heavily drunk 😉 )
CKGrafico commentedon Jun 18, 2015
Anything new about this?
mhegazy commentedon Jun 18, 2015
Arthur Ozga (@aozgaa) is looking into this
aozgaa commentedon Jun 19, 2015
I've posted an updated proposal in #3578 and made a pull request in #3579. Take a look and let me know what you think!
tinganho commentedon Jul 9, 2015
Ryan Cavanaugh (@RyanCavanaugh) Is there a way I can write a contract where on extending class's static methods has a certain signature?
React seem to want to put a lot of stuff as static members(GrahpQL, Relay). And I want some autocompletion on those only by extending a class.
RyanCavanaugh commentedon Jul 9, 2015
There isn't. Let us know if you see other cases where this would be useful - we generally didn't see a need for it.
tinganho commentedon Jul 11, 2015
Ryan Cavanaugh (@RyanCavanaugh) I have another question about abstract classes. I wonder how I define a function that accepts a derived abstract class that is not abstract and the function should also "new" it.
The following doesn't work:
RyanCavanaugh commentedon Jul 11, 2015
function testDerived(DerivedClass: new() => ComposerComponent) {tinganho commentedon Jul 29, 2015
Ryan Cavanaugh (@RyanCavanaugh) does it makes sense with optional abstract methods? I want to define an abstract class with some abstract methods on it. But I want a derived class doesn't need to implement all of the methods.
Since you allow optional on interfaces I think it makes very much sense to allow it on abstract methods as well.
RyanCavanaugh commentedon Jul 29, 2015
We don't plan to support optional class methods. It's too confusing from a consumer perspective.
You can write something like this if you want (note that these would have to be instance members, not prototype methods):
battmanz commentedon Sep 28, 2015
Why can't property getters / setters be abstract?
mhegazy commentedon Sep 28, 2015
Matt Banz (@battmanz) see #4670
vyshkant commentedon May 15, 2016
Ryan Cavanaugh (@RyanCavanaugh) The case when abstract static method can be useful is next.
I want to have one abstract class and two child classes.
Each child should have some class-dependent value (not instance-dependent).
I want to access this value without creating an instance of class.
I want to access this value when I don't know which specific child-class I'm accessing (examples below).
So I want to be sure, that every child of an abstract class has this static method.
So there is two ways to be sure that
classes[index].getSomeValue();will not cause an error:Declaring abstract static method in abstract class will resolve the problem.
ChiriVulpes commentedon Jul 8, 2016
The one use case I would really like
abstract staticfor:Unless there's another way I can go about writing a simple
Serializableinterface like this?troywweber7 commentedon Mar 8, 2017
Any progress on allowing
abstract staticmethods?RyanCavanaugh commentedon Mar 8, 2017
Please log a new suggestion issue for
abstract staticmethods - we generally don't track upvotes on comments on closed issues!troywweber7 commentedon Mar 8, 2017
Anton Dyshkant (@vyshkant) @Aarilight did your use cases go away, or are they still valid? If they are, then we should submit an issue as Ryan Cavanaugh (@RyanCavanaugh) suggests. If one of you guys starts the issue, I may eventually have a use case to add to it.
vyshkant commentedon Mar 11, 2017
@Aarilight , Troy (@troywweber7) , Ryan Cavanaugh (@RyanCavanaugh) I have created suggestion issue #14600 about this problem.