并非所有代码路径 return a value.ts(7030) angular
Not all code paths return a value.ts(7030) angular
data:any;
submit() {
this.answersValue.forEach((x: { forms: any[]; }) => {
this.data = {
pluginconfigform: "pluginconfigform",
answers: x.forms.map(y => {
if (y.type != "description") {
return {
sectionItemCode: y.code,
answer: y.answer
};
} else {
delete this.data.answers;
}
})
};
this.pushData(this.data);
});
}
你能告诉我如何解决这个错误吗? 'Not all code paths return a value.'谢谢。
enter image description here
在 delete this.data.answers;
之后添加 return y
(或未定义,或任何其他符合您的 return 的内容)。您正在使用地图,因此您需要 return 一个被映射回来的对象。如果您不想或不需要 return 任何东西,那么 return undefined 所以它会消失。
data:any;
submit() {
this.answersValue.forEach((x: { forms: any[]; }) => {
this.data = {
pluginconfigform: "pluginconfigform",
answers: x.forms.map(y => {
if (y.type != "description") {
return {
sectionItemCode: y.code,
answer: y.answer
};
} else {
delete this.data.answers;
}
})
};
this.pushData(this.data);
});
}
你能告诉我如何解决这个错误吗? 'Not all code paths return a value.'谢谢。
enter image description here
在 delete this.data.answers;
之后添加 return y
(或未定义,或任何其他符合您的 return 的内容)。您正在使用地图,因此您需要 return 一个被映射回来的对象。如果您不想或不需要 return 任何东西,那么 return undefined 所以它会消失。