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 {
The error was clarified in a later version as you see.
@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.
Most helpful comment
@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.