Home > Software design >  Not all code paths return a value.ts(7030) angular
Not all code paths return a value.ts(7030) angular

Time:05-06

  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);
    });
  }

could you let me know how to solve this error? 'Not all code paths return a value.' Thank you.

enter image description here

CodePudding user response:

Add a return y (or undefined, or anything else conform your other return) after delete this.data.answers;. You're using map so you need to return an object that gets mapped back. If you don't want or need to return anything then return undefined so it'll disappear.

  • Related