Skip to content

Extension method on interfaces and objects as in C# #57280

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

Closed
6 tasks done
muhamedkarajic opened this issue Feb 3, 2024 · 3 comments
Closed
6 tasks done

Extension method on interfaces and objects as in C# #57280

muhamedkarajic opened this issue Feb 3, 2024 · 3 comments

Comments

@muhamedkarajic
Copy link

πŸ” Search Terms

typescript extensions for interfaces

βœ… Viability Checklist

⭐ Suggestion

I think a lot of people would like this feature of being able to simply call a method in the way we can do it in C#.

πŸ“ƒ Motivating Example

E.g. if you have

interface InterfaceA {

}

that you can assign to it an extension method e.g.

function functionA(interface: Interface) { }

Then you simply can do

object: InterfaceA;
object.functionA();

πŸ’» Use Cases

  1. What do you want to use this for?
    Everywhere cause it makes the code more simple.
  2. What shortcomings exist with current approaches?
    It could be that e.g. InterfaceA has already a method called functionA. That would have to be considered.
  3. What workarounds are you using in the meantime?
    None.
@MartinJohns
Copy link
Contributor

This is explicitly out of scope for TypeScript.

You wrongly checked this:

This could be implemented without emitting different JS based on the types of the expressions

@xiBread
Copy link

xiBread commented Feb 3, 2024

Also a duplicate of #45968

@muhamedkarajic
Copy link
Author

This is explicitly out of scope for TypeScript.

You wrongly checked this:

This could be implemented without emitting different JS based on the types of the expressions

My bad.

Also a duplicate of #45968

Ty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants