“TypeScript is a smart choice when writing a modern web- or JavaScript-based application. TypeScript’s carefully considered language features and functionality, and its consistently improving tools, result in a terrifically productive development experience.”. At the moment VSCode does not auto-generate code for the abstract function. VSCode does not do any code generation for TypeScript. It is all generated via the TypeScript compiler. Furthermore, the TypeScript language service itself is responsible for producing errors in VSCode. Ide plugins like tslint can produce warnings.
I think that template method means that a subclass has to implement a method that is used in abstract class (for example in base render method) and it is assumed that this method cannot return any default value for being abstract. If it could, then just specifying this default value in abstract base would be enough.The point here in favor of abstract properties (and I mentioned it earlier) is that it is not Java and devs should not be forced to use Java-style methods to access a simple value. I mean that I don't need pairs of getValue/ setValue per each field. Moreover, everything related to runtime checks and exception throwing is undesired - we have static checking for that.Also, what do you think about instance-bound handlers which are described in my previous message update?
It seems like I've updated it too late and you haven't noticed that. Yes I did respond as soon as I was notified:) Re 'instance-bound handlers' I don't understand why the abstract class Popup requires its subclasses to return void from onClose when it needs to return an object (i.e. Hash / dictionary)?Re: 'template method',a subclass has to implement a method that is used in abstract classThat's correct, but we're referring to properties. As mhegazy said earlier:declaring the property as abstract does not change anything different from just declaring it.
The type is going to always have the property.As for getters and setters., the type system does not differentiate between getter/setter and a property declaration. Sorry I don't understand. I agree that:. an abstract class should enforce its subclasses to implement abstract methods.I also think that:. an abstract class declaring any property should not enforce a subclass to implement a get or set method as what implementation is required?Again even a partially concrete use case would be very useful to understand what problem you are trying to solve and how you think abstract properties would help.
Is it that you want the abstract class to force the subclass to initialise the property? Or provide some particular functionality? Or something else? Dart have abstract properties and uses them quite a lot in the standard library in a very nice way.For example List which is an abstract class and have abstract getters for things like length, reversed and similar things that classes implementing a List need to implement.I can't see how a language that have getters and setters can justify abstract methods but not abstract properties. They are the same thing just with a nicer syntax. If you don't think abstract properties are needed you should think that abstract methods are equally needless.
And of course abstract methods are valuable, they force subclasses to implement them.Just as abstract properties forces subclasses to implement them. They are the same thing.So is it only a case for brevity?Mostly, however I would argue that it's about intention as well.
A property should never have a side effect, methods might. Mixing Java style getters with good getters makes the code more confusing.Or is there a pattern in TypeScript that you just can't achieve without abstract properties?We could probably think of some strange edge case where some library expect a good getter but I would say no. You can manage just fine without them.
But you can manage just fine without abstract methods as well by having an abstract class implement an interface. But that doesn't mean that it's the clearest way to express yourself.I would totally understand declining abstract properties if there were no abstract methods but when you already have the concept of abstract things I can't understand why not all methods can be abstract. It makes the language harder to learn and understand when you have to remember all special cases for different kinds of methods.
Thanks:) I feel due to the similar nature of the bug report you made me aware of (which I also commented on) that I should justify this bug report. This one is for an abstract property (the other bug report is not). Since an abstract property must be extended in a sub class. The current implementation means it would never have a property accessible within the constructor of the base class and clearly shows it will be overwritten (and enforced) so it makes no sense to declare it in the base class in the first place.In my opinion, not having access to such an extended property within the parent constructor seems nonsensical especially given the nature of an abstract. What would provide a clearer indication to the access (scope) of such a property would be to add the property to an interface instead of marking as abstract allowing it to be completely removed from the base class making it less likely a programmer will accidentally try to access it within the base class constructor. But, if they did try to access it they would then fall prey to a bug of similar nature to.It's crazy how many gotchas are appearing because of the way this sub classing around properties are implemented. Yet the reasoning behind why it was implemented this way appear due to technical reasons and not for reasons of what the community was expecting.I feel abstract properties with the way they are currently implemented is very easy for someone using them to be tripped up.
In programming languages you're sort of stuck doing thought experiments.Can't disagree with you there.Base should never be able to observe itself in a state where its properties have been uninitialized.Brains now scrambled:pPeople keep clamoring for solutions which are not available, in opposition to the technical evidence, and it's very frustrating.Programmers ay;) This is TypeScript, can you not implement it how you like? Just winding you up:pI've just read this (sorry, should have read this before continuing this discussion):Align with current and future ECMAScript proposals.Guess you have no choice;) I was somewhat assuming you had a bit more flexibility in applying restrictions using the compiler and the typescript way to help guide people down a friendlier path but appears your hands are tied.I would suggest adding in some more compile time error checks though around accidental misuse/misunderstanding of typescripts abstract implementation. If nothing else is gained from this discussion.Thanks for your time in discussing this. Didn't intend to provoke you especially since you're drastically more experienced on this subject than myself. No doubt will be bumping into you again around here some time:).