Created
March 22, 2021 19:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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