TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

TS cannot find type (type is unknown) for extension of Map class

Open ORESoftware opened this issue 3 years ago • 2 comments

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:

Screen Shot 2022-11-27 at 2 48 13 PM

Seems like just an improvement could be made here.

ORESoftware avatar Nov 27 '22 20:11 ORESoftware

if it's not clear, the type of v is unknown

ORESoftware avatar Nov 27 '22 23:11 ORESoftware

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 []

fatcerberus avatar Nov 28 '22 16:11 fatcerberus

This issue has been marked as 'Not a Defect' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

github-actions[bot] avatar Jun 08 '23 03:06 github-actions[bot]