Skip to content

Flow reports implicitly returned undefined even when not possible #3366

@Gozala

Description

@Gozala

I keep running into more complex version of this example code fairly often:

/* @flow */

const exmpl = (input:number):number => {
  while (true) {
    switch (input) {
      case 0:
        return input
      default:
        return 0
    }
  }
}

Which flow fails to type check with a following error:

3: const exmpl = (input:number):number => {
                                ^ number. This type is incompatible with an implicitly-returned undefined.

Most likely flow is failing to infer that while block will ever be executed. I am not sure how difficult would it be make flow type check this code, but either way it would really help if flow provided a hint on why it assumes implicitly returned undefined something, telling user that while block may never run would greatly improve usability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions