2

Lately I had to debug a test that had been written in TypeScript and has been run via ts-mocha. So, actually I had to debug the transpiler output sorta directly. And in lines like this:

(0, expect_1.default)(loadedTask.name).toBe(newTask.name);

only this (0, expression) wrapping got me confused. What is purpose of this (0, expr) wrapping? What JS gotcha this wrapping should prevent or workaround?

Thanks for your answers and time.

Kote Isaev
  • 273
  • 4
  • 13
  • 1
    It's to produce spec-compliant imports so that imported functions would have the proper `this` context. See [the answer](https://stackoverflow.com/a/69633435/2887218) to the linked question for more information. – jcalz Dec 10 '21 at 14:57
  • 1
    Thanks. I just was not able to ask the question the proper way at search bar, although I tried few different variants, before asking the question. It surely answers and brings sense to `(0,expr)` syntax. JS may be need some "access without `this` operator like `->` or `:>` to explicitly say to JS compiler what it is about, and to process this faster . – Kote Isaev Dec 10 '21 at 15:49

0 Answers0