What is the Reason for the (0,
Pattern in Transpiled JavaScript?
When looking at transpiled JavaScript from TypeScript, I often see the pattern (0, someFunction)(...)
. For example, this TypeScript code:
await formatFiles(tree);
compiles to this JavaScript:
await (0, _devkit.formatFiles)(tree);
I’m wondering what is the reason for the (0,
pattern? As far as I understand the comma operator, it evaluates each expression, throws away the value of all but the last, and returns that last value. However, the expression 0
doesn’t have side effects; it doesn’t do anything. So, (0, _devkit.formatFiles)
is equivalent to _devkit.formatFiles
.
Am I missing something? Does the (0,
pattern actually do something?