-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript should have shorthand get syntax like C# 6.0 #10911
Comments
I suspect this will fall under TypeScript design goal:
And be considered the domain of ECMAScript/JavaScript and that if TC39 agreed to that sort of shorthand, then TypeScript would gladly implement... This was discussed on ESDiscuss here and there were several reasons why it was not considered a good idea. In particular, the arrow functions in ECMAScript bind to the lexical |
Oh, and non-goal:
|
@kitsonk I think this could be accomplished by modifying the automatic field creation from constructor arguments annotated with the That said, personally I think that decorators would be a better way to accomplish this. The problem being that they do not affect the type of decorated class. If they did affect the type, class or constructor parameter decorators could accomplish this goal. I am thinking something like class Car {
constructor(@get public make, @get public model, @get @set public miles) { }
} |
One persons adopting useful expression level syntax is another person's mimicking existing languages. The biggest challenge with decorators is they don't mutate types. We may see something that would work in 2.1 if the core team gets the time to address ambient decorators. |
@kitsonk I agree, and I did indeed mention that my decorator based example would only work if decorators mutated types. Regarding expression level syntax, my reasoning here was that since TypeScript already allows placing |
Proposal
TypeScipt should have shorthand syntax for get properties. Please note that this is related to another of my proposals for TypeScript; notably, the ability to output value properties as well as accessor properties.
Rationale
I want to write fewer lines of code and express intent more clearly
What I have to write currently
What I would like to write
public get mySuperObjectProperty(): SomeType => this.mySuperObjectPropertiesBackingVariable;
On a serious note, TypeScript's property implementation is hideous, and could be much improved to bring it inline with property implementation as of ES5...again, check out my proposal for value properties.
The text was updated successfully, but these errors were encountered: