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
This proposal aims to introduce a method reference syntax in TypeScript to make the language more intuitive and less prone to common errors related to function context. By adopting this feature, TypeScript could offer a cleaner, more logical way to handle method references, aligning with the language's goal of enhancing JavaScript with improved tooling.
π Motivating Example
A method reference syntax could offer a more intuitive way to pass methods as callbacks, making the code cleaner and less prone to common mistakes.
What do you want to use this for?
I aim to use this feature to simplify and improve the readability of code when passing methods as callbacks. This would be especially beneficial in scenarios where preserving the this context is crucial. By reducing boilerplate and eliminating redundancy, we can make the code more maintainable and less error-prone.
What shortcomings exist with current approaches?
Confusing Syntax: The current syntax options, such as .bind(this) and arrow functions, can be confusing and counterintuitive. The redundancy in .bind(this) and the misleading appearance of arrow functions can lead to mistakes.
Missed Opportunity for Intuitiveness: TypeScript has the chance to adopt a syntax that makes it clear that a method reference is being passed without any additional logic or immediate invocation. This would align TypeScript more closely with functional programming paradigms and make the language more intuitive.
What workarounds are you using in the meantime?
In the absence of a method reference syntax, developers are left with suboptimal solutions like .bind(this) and arrow functions. These workarounds are functional, but fall short of the elegance and readability that could be achieved with a dedicated syntax for this purpose.
The text was updated successfully, but these errors were encountered:
Duplicate of #3508. Used search terms: bind in:title
aligning with the language's goal of enhancing JavaScript with improved tooling.
In general, because based on your issue you're not aware of it, the goal of TypeScript is not just to improve JavaScript with improved tooling, but to add type information to JavaScript - and only that. Adding syntax that is beyond the type-only level (like your suggestion) and does not exist in JavaScript is explicitly out of scope (as mentioned in the viability checklist).
π Search Terms
"method reference", "double colon operator", ":: syntax", "Java-like method reference"
β Viability Checklist
β Suggestion
This proposal aims to introduce a method reference syntax in TypeScript to make the language more intuitive and less prone to common errors related to function context. By adopting this feature, TypeScript could offer a cleaner, more logical way to handle method references, aligning with the language's goal of enhancing JavaScript with improved tooling.
π Motivating Example
A method reference syntax could offer a more intuitive way to pass methods as callbacks, making the code cleaner and less prone to common mistakes.
Desired TypeScript Example:
π» Use Cases
What do you want to use this for?
I aim to use this feature to simplify and improve the readability of code when passing methods as callbacks. This would be especially beneficial in scenarios where preserving the
this
context is crucial. By reducing boilerplate and eliminating redundancy, we can make the code more maintainable and less error-prone.What shortcomings exist with current approaches?
Confusing Syntax: The current syntax options, such as .bind(this) and arrow functions, can be confusing and counterintuitive. The redundancy in .bind(this) and the misleading appearance of arrow functions can lead to mistakes.
Missed Opportunity for Intuitiveness: TypeScript has the chance to adopt a syntax that makes it clear that a method reference is being passed without any additional logic or immediate invocation. This would align TypeScript more closely with functional programming paradigms and make the language more intuitive.
In the absence of a method reference syntax, developers are left with suboptimal solutions like
.bind(this)
and arrow functions. These workarounds are functional, but fall short of the elegance and readability that could be achieved with a dedicated syntax for this purpose.The text was updated successfully, but these errors were encountered: