-
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
Extension methods for interfaces #24889
Comments
Unfortunately if the proposal is that that syntax enables users to write declare let x: Rect;
x.area() then this would be type-directed syntax, and also falls out of our design goals in that it extends ECMAScript past the type space. You might want to keep an eye on the pipeline operator ( |
Interesting. Thanks for pointers. Different operator, however, does not fix discoverability problem as everyone is just used to typing dot and get suggestions. |
Duplicate of #9 |
@oliverjanik no, read the thread, it was closed because it was deemed out of scope, because there are some major problems with implementation that make it not practical to be considered. Because people were not reading the thread and understanding that it is not implementable, the whole thread had to be locked. This is asking exactly for a feature which is out of scope, so it is a duplicate. |
I understand it's impractical and type driven syntax. On the other hand it's impossible in plain JS because JS doesn't know about interfaces. They're compiled away. So while you can monkey-patch classes in JS, interfaces will never be possible. Not sure if there's any way forward on this. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
@oliverjanik I'm facing the same limitation (no instance methods on objects deserealized from JSON). What's the best way you found to work around it? |
Apologies I this is a dup.
The situation comes up often. I define an interfaces for my API JSON responses and I wish they were classes so I could define instance methods on them. Say for mutation, or just helpful convenience methods.
Sure I can use standalone functions that take the interface as the first parameter but discover-ability sucks.
Something like this:
The text was updated successfully, but these errors were encountered: