angulartypescriptecmascript-next

How to make new Map.groupBy work in TypeScript/Angular project?


I want to use the new Map.groupBy function in an NX/Angular/TypeScript project, but this is not working.

I had IDE errors saying that the function is unrecognized. I've fixed that updating tsconfig.base.json file to use ESNext:

"lib": ["ESNext", "dom"],

Now my unit tests are not working at runtime due to a similar error:

Map.groupBy is not a function
TypeError: Map.groupBy is not a function

What are the requirements to make it work?


Solution

  • This functionnality only works with node version >= 21.0.0 and I was using a lower version

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy#browser_compatibility