Why does flow throw an error using an object as Reference here:
type LoadUserData = { type: actionTypes.LOAD_USER_DATA, user: User };
But when a string is used no error is thrown:
type LoadUserData = { type: "LOAD_USER_DATA", user: User };
The error that is thrown is:
Error:(8, 29) Flow: string. Ineligible value used in/as type annotation (did you forget 'typeof'?) LOAD_USER_DATA
Unfortunately,
Flow
doesn't allow you to use constants within your type definitions. It must either be a data type or a constant value, but no variables. Therefore, you'll have to stick with the:I'm assuming this is a type definition for a
Redux
action, in which case, Facebook's docs actually recommend this anyway!You can use
typeof
as it suggests, but that probably won't do what you want:This happens because Flow infers the type of
actionTypes.LOAD_USER_DATA
to bestring
.Unfortunately for your use case you will probably have to just write out the string literals again in the type.