Skip to content

Instantly share code, notes, and snippets.

@kerren
Created March 22, 2021 19:18
Show Gist options
  • Save kerren/cb10a09210540301c8de0d4a371e8af0 to your computer and use it in GitHub Desktop.
Save kerren/cb10a09210540301c8de0d4a371e8af0 to your computer and use it in GitHub Desktop.
[A map key] A map can take any type of key! #map #typescript
const map = new Map();
map.set(1, 'simple');
console.log(map.get(1));
// 'simple'
const person = {
name: 'John',
surname: 'Doe'
};
map.set(person, true);
console.log(map.get(person));
// true
class MyClass {
public hello() {
console.log('hello');
}
}
map.set(MyClass, {...map.get(MyClass), internal: true });
map.set(MyClass, {...map.get(MyClass), beta: true });
console.log(map.get(MyClass));
// {
// internal: true,
// beta: true
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment