Why the infered type of this function is `string | undefined`?

Why the infered type of this function is string | undefined? How TypeScript is unable to see that the returned value can never be
undefined
?

export const myFunction = (
  { value1 }: { value1?: string },
  value2?: string
) => {
  if (!value1 && !value2) {
    throw new Error("No value provided.");
  }

  return value1 ?? value2;
};
Screenshot_2023-08-09_at_13.38.36.png
Was this page helpful?