Map objects are not being handled properly during conversion from typescript to google apps script
(Note: Non-breaking issues are likely not to be prioritized. Please consider a PR in addition to your issue)
Expected Behavior
When pushing a project written in TypeScript, it would be expected that a for...of loop applied on a map iterator (such as the return of map.entries() and map.keys()) would result on an executable loop on google apps script.
Also, the piece of code [...map_object.entries()] should return an array that contains sub-arrays filled with key-value pairs (like [[key1, value1], [key2, value2], ... , [keyN, valueN]]).
Actual Behavior
When pushing a project, for...of loops applied to map iterators have their code replaced to non-executable loops (like for (var _i = 0, _a = map_object.entries(); _i < _a.length; _i++)
Also, the convertion does not handle the piece of code [...map_object.entries()] properly, since it's converted to a piece of code that returns an empty array (__spreadArray([], data_map.entries(), true)).
Steps to Reproduce the Problem
- On a GAS project, add a .ts file.
- Create a map object, such as
const map_object = new Map(); - Add an entry to the map object, such as
map_object.set("key1", "value1");. - Write a
for...ofloop such asfor (const entry of map_object.entries()). - Inside the loop, write
Logger.log(entry);. - Outside the loop, add the line
Logger.log([...map_object.entries()]);. - Push the project to GAS.
- Check and run the code on GAS and check the log.
Specifications
- Node version (
node -v): v16.14.0 - Version (
clasp -v): 2.4.1 - OS (Mac/Linux/Windows): Windows
I have also encountered this issue
I don't know why clasp can't just compile to ES6. This issue can easily be mitigated
The workaround is to use typescript and add this to the tsconfig.json:
{
"compilerOptions": {
"lib": ["esnext"],
"experimentalDecorators": true,
"target": "ES2015"
}
}