I'm defining and implementing a Map class in TypeScript which also uses the built-in Map class (with generics). Obviously the names clash. Can I somehow import the built-in Map using explicit namespace (like one would do in Java) or is there a different way to resolve a conflict like this?
export class Map // my map
{
private readonly items: Map<string, string>; // built-in map
}
I've looked through the TS core definition files but can't figure out if they use any namespace.
I stumbled upon this question myself so I might as well provide a response after quite a bit of time wasted trying to find an answer myself.
In modern browsers, the global namespace can be accessed via the global variable 'globalThis' (e.g. globalThis.Map).
You'll need a polyfill to get this working in old browsers such as EdgeHTML.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With