Ad
  • Default User Avatar

    It's because in typescript, all code paths must have a return value that matches the expected return type. In your original example, what if all of your if conditions are false? If that happens, there is no return value, so it returns undefined, but undefined is not a string, so it can't compile. Logically, we know that that can't really happen, because all possible values of bmiCalc are covered by all of your if conditions, but the compiler isn't that smart. The compiler only sees that there are a bunch of if conditions, and there is no return value specified if all if conditions are false. Alternatively, you can fix this by putting something like return "blah" after your last if block.