Imagine having a Map structure like the one found in file CategoryMap.ts
export default new Map<number, SubCategory[]>([
[11, [100, 101]],
[12, [102, 103]],
...
])
Is there a way to create a type guard for this Map?
import categoryMap from 'CategoryMap'
type CategoryMapId = keyof typeof categoryMap
function isCategoryId(id: number): id is CategoryMapId {
return categoryMap.has(id)
}
The issue here is that CategoryMapId
appears as
"[Symbol.toStringTag]" | "clear" | "delete" | "forEach" | "get" | "has" | "set" | "size" | "[Symbol.iterator]" | "entries" | "keys" | ...
What I would like is for the type CategoryMapId
to be 11 | 12 ...
Any ideas on how to solve this? Thanks.