可以肯定,我的逻辑要复杂得多,但这是一个占位符代码,我试图停止递归调用,但break关键字说Jump target cannot cross function boundary .ts(1107)
let arr = [1, 2, 3, 4, 5, 6, 7, 8];
async function recCall(input: number[]) {
if (input.length) {
let eachItem = input.pop();
// my logic includes http call with await
recCall(input); // next iter
}else{
break; // says error
}
};
这不是普通的javascript,而是打字稿,我的打字稿版本是:
tsc -v
Version 3.7.5
我无法理解此错误的含义以及发生原因,我在互联网上进行了搜索,但没有发现任何原因,过去几年我一直在使用break来中断循环,现在显然开始无法正常工作了,说我不明白的错误任何帮助都将得到应用。
您没有中断的循环。使用return
代替
let arr = [1, 2, 3, 4, 5, 6, 7, 8];
async function recCall(input: number[]) {
if (input.length) {
let eachItem = input.pop();
// my logic includes http call with await
recCall(input); // next iter
}else{
return;
}
};