Issue with HashMap Key and Data Class in TypeScript

I have a HashMap<Key, Value> with Key being:
export class Key extends Data.Class<{
  id: string;
  provider: string;
}> {}

I just found a bug because in some function, I was doing something like:
const getKey = (): Key => ({ id: "...", provider: "..." });

Thus, not having the Hash and Equal traits implemented on the output - although the return type is typed as Key - which breaks the HashMap.

If I type my Key as:
export interface Key extends Hash.Hash { 
  id: string, 
  provider: string 
}

Then I get typesafety but the Data.struct function does not comply with the type. I feel like that is the whole purpose of Data to have those traits so it feels strange having this confusion in the resulting type, shouldn't the Data methods return T & Hash & Equal? What is the recommended way to deal with those types?
Was this page helpful?