DEV Community

Discussion on: Typescript for beginners: how to ignore code

Collapse
 
emahuni profile image
Emmanuel Mahuni

What actually wanted to do is make the compiler ignore the line completely and not even compile it. The reason is it's changing the code in such a way that it becomes useless. So I wanted ts to actually ignore the line completely and move to the next. In other words copy the line as it is and paste it in the output code.
I want the following line to remain that way:

isAsyncFunction = (fn: Function) => fn instanceof Object.getPrototypeOf(async function(){}).constructor;
Enter fullscreen mode Exit fullscreen mode

ts compiles this to:

isAsyncFunction = (fn) => fn instanceof Object.getPrototypeOf(function () {
    return __awaiter(this, void 0, void 0, function* () { });
}).constructor;
Enter fullscreen mode Exit fullscreen mode

I want it to at least not change how the line is going to behave.

Collapse
 
emahuni profile image
Emmanuel Mahuni • Edited

What I ended up doing was protect the code in an eval statement.