You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Misleading value-as-type errors on type identifiers that aren't properly typed #8547
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 {
Reacted by Juanchi Rios, evbo, Mike Young, Mike Staub, budowski and Max Claus
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
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
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
@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.
Activity
[-]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[/+][-]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[/+][-]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[/+]gkz commentedon Dec 4, 2020
The error was clarified in a later version as you see.
jedwards1211 commentedon Dec 4, 2020
@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-typewhich 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.