在可视化代码中调试 Angular/Typescript 将“_1"附加到变量 [英] Debug Angular/Typescript in visual code appends '_1' to variable
问题描述
我正在尝试在 Visual Code 中调试 angular/typescript 应用程序.假设我运行以下代码
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);
}
假设发生了错误,我将在控制台中看到为正常执行记录的错误.我面临的问题是,如果我在调试模式下运行相同的情况(针对本地主机启动 Chrome").我会得到:
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"
如果我在调试视图中查看关闭"部分而不是本地"部分.我可以访问 error_
,其中确实包含正常执行中通常记录的内容.
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.
有没有办法在 angular/的调试模式下将错误视为 error
而不是 error_1
打字稿应用?
Is there a way to view the error as error
instead of error_1
in debug mode for angular/typescript application?
我尝试了来自 Typescript/babel 导入的建议,导致_1.default is not a function"; 没有任何成功.
I tried a suggestion from Typescript/babel import causing "_1.default is not a function" without any success.
推荐答案
当 ts config 中的 ECMAScript target 版本低于 ES6 时,会发生这种情况.
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.
这可能是因为 async/await 函数被改写为 __awaiter __generator 形式.它甚至没有在这里使用 try catch 概念...
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*/];
}
});
});
};
这篇关于在可视化代码中调试 Angular/Typescript 将“_1"附加到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!