TypeScript
TypeScript copied to clipboard
TS cannot find type (type is unknown) for extension of Map class
Suggestion
Love TS! Here is a bit where type inferences seems to be lacking.
Here is the raw code:
export class DESMap<K,V> extends Map<K,V> {
constructor() {
super();
}
toJSON(){
return Array.from(Object.fromEntries(this)).map((v) => {
return [v[0], v.value];
});
}
}
Here is the lack of inference:
Seems like just an improvement could be made here.
if it's not clear, the type of v is unknown
This code doesn't actually work:
const map = new DESMap<string, string>();
map.set("foo", "bar");
console.log(Object.fromEntries(map)); // prints { "foo": "bar" }
console.log(map.toJSON()); // prints []
This issue has been marked as 'Not a Defect' and has seen no recent activity. It has been automatically closed for house-keeping purposes.