Skip to content

Misleading value-as-type errors on type identifiers that aren't properly typed #8547

Open

Description

@jedwards1211

If an identifier is declared as a type, we should never ever see "value-as-type" errors on that identifier.

But after upgrading from flow 0.125.1 to 0.133.0, I'm getting a bunch of errors like this:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/server/context/connectEvents.js:45:19

Cannot use DeviceInputState as a type. A name can be used as a type only if it refers to a type, interface, class, or
enum definition. To get the type of a non-class value, use typeof. [value-as-type]

     42│       EVENT_DEVICE_INPUT_STATES,
     43│       (deviceInputStates: DeviceInputStates) => {
     44│         const mainBoardStatus: ?DeviceInputState = deviceInputStates.inputStates.find(
     45│           (state: DeviceInputState) => state.address === 1
     46│         )
     47│         if (mainBoardStatus) {
     48│           const {

I'm definitely importing DeviceInputState as a type. Turns out it's because I forgot a @flow annotation in the file that's exporting DeviceInputState.

It seems that Flow's internal model now treats identifiers as belonging to one of two categories: properly typed, or value. Flow needs to model a third "improperly typed" category for the sake of sane error reporting.

In this case Flow should be claiming that it can't import the type, not that the identifier is a value.

It was only after I upgraded to 0.138.0 and configured types_first=false that the error gave me a clue what was wrong:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/server/context/connectEvents.js:45:19

Cannot use DeviceInputState as a type because it is an any-typed value. Type DeviceInputState properly, so it is no
longer any-typed, to use it as an annotation. [value-as-type]

     42│       EVENT_DEVICE_INPUT_STATES,
     43│       (deviceInputStates: DeviceInputStates) => {
     44│         const mainBoardStatus: ?DeviceInputState = deviceInputStates.inputStates.find(
     45│           (state: DeviceInputState) => state.address === 1
     46│         )
     47│         if (mainBoardStatus) {
     48│           const {

Activity

  1. changed the title [-]Flow 0.133.0 thinks a bunch of imported types are values; giving bogus value-as-type errors[/-] [+]Flow 0.133.0 gives confusing value-as-type on imported type identifiers if exporting file lacks @flow annotation[/+] on Dec 3, 2020
  2. changed the title [-]Flow 0.133.0 gives confusing value-as-type on imported type identifiers if exporting file lacks @flow annotation[/-] [+]Misleading value-as-type errors on imported type identifiers if exporting file lacks @flow annotation[/+] on Dec 3, 2020
  3. changed the title [-]Misleading value-as-type errors on imported type identifiers if exporting file lacks @flow annotation[/-] [+]Misleading value-as-type errors on type identifiers that aren't properly typed[/+] on Dec 3, 2020
  4. gkz commented on Dec 4, 2020

    @gkz
    Member

    The error was clarified in a later version as you see.

  5. jedwards1211 commented on Dec 4, 2020

    @jedwards1211
    ContributorAuthor

    @gkz just barely, I mean I was able to figure out the problem, but it still says "any-typed value" when it's not a value at all, and mostly importantly the error code is still value-as-type which I don't think should be acceptable if the identifier is not a value. These errors should be distinguished, with a different code, from cases where we mistakenly use an actual value identifier where a type identifier belongs. If improperly typed identifiers hadn't been carelessly lumped together with value identifiers, we would have never gotten a confusing error message in earlier versions.

  6. self-assigned this
    on Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions