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
//import "./extensions"
var data = [1, 2, 3]
var peek = data.peek()
console.log(peek)
Expected behavior:
I would like to have the ability to import extension methods and interfaces on a module basis. This would allow you to import an extension method interface and its implementation on an as-needed basis, or importing different implementations of an extension method. A good example of the desired behavior is in C# where you import a namespace to gain access to the extension method. Without that namespace, the extension method will not be present. Actual behavior:
As far as I'm aware, extension methods in typescript must be declared on a global basis, meaning in a code editor like VS Code, you can only declare an extension method interface on a global level. This means you must ensure the implementation is loaded globally, or you will create an odd situation where you have a method in TypeScript, but not the implementation in JavaScript.
The text was updated successfully, but these errors were encountered:
I can't stress enough how bad of a plan this is. When you modify the prototype, you do so for everyone. And if you have "different implementations of an extension method", you really cannot predict which one was the last one in.
Our current support for declare global is all we intend to do here. Don't modify built-in prototypes. It's not worth the future pain you're going to incur on yourself or others.
It's odd to see Microsoft so anti-extension-functionality in TypeScript when it's not only highly used in C#, but is actually being pushed to "extension everything" in future language versions.
declare global seems to be more of a hack workaround imo.
Alright, this was just a request, thanks for the feedback
TypeScript Version: 2.7.2
Search Terms: global modules declarations extensions VS Code
Code
extensions.ts:
main.ts:
Expected behavior:
I would like to have the ability to import extension methods and interfaces on a module basis. This would allow you to import an extension method interface and its implementation on an as-needed basis, or importing different implementations of an extension method. A good example of the desired behavior is in C# where you import a namespace to gain access to the extension method. Without that namespace, the extension method will not be present.
Actual behavior:
As far as I'm aware, extension methods in typescript must be declared on a global basis, meaning in a code editor like VS Code, you can only declare an extension method interface on a global level. This means you must ensure the implementation is loaded globally, or you will create an odd situation where you have a method in TypeScript, but not the implementation in JavaScript.
The text was updated successfully, but these errors were encountered: