I tried to ask a question on the typescript subreddit and they've yet to approve the post, so I'm hoping I can get a quicker response here.
Can anyone explain why I am getting an error on the last line where I try to reference a member of the map? Any member, not just entries() results in the same error: Uncaught (in promise) TypeError: newDraft.itemsPerCategory.entries is not a function. It seems like there is no way to get the interpreter to recognize that the parsed json is of type DraftOrder (despite the fact that I see the DraftOrder type hint in my IDE).
export class DraftOrder {
itemsPerCategory: Map
constructor(itemsPerCategory: Map ) { this.itemsPerCategory = itemsPerCategory }
static empty (): DraftOrder { return new DraftOrder(new Map ) }
}
// Creating new draft, converting to json const map = new Map ([[ LaundryCategory .LIGHT, 2], [ LaundryCategory .MEDIUM, 3]]) const jsonString = JSON .stringify( new DraftOrder(map), (_, value) => { if (value instanceof Map ) { return Object…