import { Optional } from '../typings/standard-types' export default class LocalWeakMap { private weakMap: WeakMap, V> private map: Map constructor() { this.weakMap = new WeakMap() this.map = new Map() } set(key: K, value: V): void { if (typeof key === 'object') { this.weakMap.set((key as unknown) as Record, value) } else { this.map.set(key, value) } } get(key: K): Optional { if (typeof key === 'object') { return this.weakMap.get((key as unknown) as Record) } return this.map.get(key) } has(key: K): boolean { if (typeof key === 'object') { return this.weakMap.has((key as unknown) as Record) } return this.map.has(key) } }