3 ms·
Any plans to add C#-like extension methods to TypeScript? Or is there a way to achieve the same thing already? I know that a previous suggestion to add extensio
by mwcampbell 10y ago
Any plans to add C#-like extension methods to TypeScript? Or is there a way to achieve the same thing already? I know that a previous suggestion to add extension methods was closed as out of scope. But maybe it's time to revisit that, since TypeScript is now doing significant code transformations for downlevel await support.
- patates 10y agoJavaScript already allows you to do something very similar to extension methods by extending prototypes. OTOH, a function accepting an object which implements a specific interface as a parameter will make your code much more easier to extend, instead of modifying the prototype of a concrete class.
- tomatsu 10y agoThe bind operator (::) would allow you to write "virtual methods". https://github.com/tc39/proposal-bind-operator https://github.com/tc39/proposal-bind-operator (stage 0)
- RyanCavanaugh 10y agoIt's not possible to add extension methods to TS in a way that would be usable in practice. https://github.com/Microsoft/TypeScript/issues/9 https://github.com/Microsoft/TypeScript/issues/9 has a long discussion of the problems with trying to do this.