Debug Angular/Typescript in visual code appends '_1' to variable

Viewed 481

I am trying to debug an angular/typescript application in Visual Code. Let's say I run the following code

try {
    ...
} catch (error) {
    console.log(error);
}

Assume an error occurs, I will see in my console the error being logged for a normal execution. The issue I face is that if I run the same situation in debug mode ("Launch Chrome against localhost"). I will get:

"Uncaught ReferenceError: error is not defined"

If I look at the 'Closure' section instead of the 'Local' section in the debug view. I have access to error_ which indeed contains what normally gets logged in a normal execution.

Is there a way to view the error as error instead of error_1 in debug mode for angular/typescript application?

I tried a suggestion from Typescript/babel import causing "_1.default is not a function" without any success.

Error preview

1 Answers

That thing happens when ECMAScript target version in ts config is below ES6.

{
  "compilerOptions": {
    "target": "ES5",
  }
}

If you can't increase it then there is no solution.

Perhaps this is caused by async/await function is being rewritten into __awaiter __generator form. It doesn't even use try catch concept here...

 AppComponent.prototype.functionInComponent = function () {
        return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function () {
            var error_1;
            return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__generator"])(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        _a.trys.push([0, 1, , 3]);
                        ...
                    case 1:
                        error_1 = _a.sent();
                        ...
                        return [4 /*yield*/, asyncFunctionAfterConsoleLog];
                    case 2:
                        _a.sent();
                        return [3 /*break*/, 3];
                    case 3: return [2 /*return*/];
                }
            });
        });
    };
Related