When working with TypeScript, I keep encountering an error message that reads "cannot find name Map."
var myMap = new Map();
var keyString = "a string",
keyObj = {},
keyFunc = function () {};
// assigning values to keys
myMap.set(keyString, "value associated with 'a string'");
myMap.set(keyObj, "value associated with keyObj");
myMap.set(keyFunc, "value associated with keyFunc");
myMap.size; // 3
// retrieving the values
myMap.get(keyString); // "value associated with 'a string'"
myMap.get(keyObj); // "value associated with keyObj"
myMap.get(keyFunc); // "value associated with keyFunc"
myMap.get("a string"); // "value associated with 'a string'"
// because keyString === 'a string'
myMap.get({}); // undefined, because keyObj !== {}
myMap.get(function() {}) // undefined, because keyFunc !== function () {}
I am puzzled as to why this issue is occurring.
Besides, JavaScript does indeed have a Map
.
I would greatly appreciate any assistance provided.