练习Javascript,如果我想测试一个代码块
function logic(a, b){
x= a+b;
y = x-5;
console.log(y);
return; // This is my break statement to make sure the function runs until y.
z = y*10; //This line is not executed.
}现在,在使用angular2练习打字本时,如果我使用返回
logic(a, b) => {
x= a+b;
y = x-5;
console.log(y);
return; // Throws error
z = y*10; //I need to comment out this line to avoid error
}它说无法到达的代码检测到了。我有没有办法阻止死刑。
答案是更新根文件夹中的tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowUnreachableCode": true, //add this line
"lib": [
"es2016"
]
}
}发布于 2017-03-07 10:57:06
是的,设置--allowUnreachableCode。请参阅:https://www.typescriptlang.org/docs/handbook/compiler-options.html
https://stackoverflow.com/questions/42646302
复制相似问题