We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi, I'm trying to use disjoint unions to check a redux reducer. I have a constants file where I export all my constants, like this:
constants
export const USERS_LOAD = "USERS_LOAD"; export const USERS_LOADED = "USERS_LOADED";
The problem is, if I import this constants and define my type Action like this:
type Action
type Action = | { type: typeof USERS_LOADED, users: Array<{}>} | { type: typeof API_ERROR, error: ?any} | { type: typeof USERS_LOAD };
And use it un my code like this:
function users(state: State = { loading: false, all: [], }, action: Action): State { switch (action.type) { case USERS_LOAD : return { ...state, loading: true, }; case USERS_LOADED : return { loading: false, all: action.users.map(user => new User(user)), error: null, }; default : return state; } }
I get the error in USERS_LOADED case: Property not found in action
USERS_LOADED
However, if I define the constants directly in the file instead of importing them, the error goes away and works like expected
The text was updated successfully, but these errors were encountered:
typeof USERS_LOAD is string and not literal 'USERS_LOAD': example. See also: #2639.
typeof USERS_LOAD
string
'USERS_LOAD'
Sorry, something went wrong.
You're right. I changed that because without typeof I get the error
typeof
Ineligible value used in/as type annotation (did you forget 'typeof'?)
So, the real question is? Can I use the disjoint types with constants like I said, or it must be using literals?
#4175
No branches or pull requests
Hi, I'm trying to use disjoint unions to check a redux reducer. I have a
constants
file where I export all my constants, like this:The problem is, if I import this constants and define my
type Action
like this:And use it un my code like this:
I get the error in
USERS_LOADED
case: Property not found in actionHowever, if I define the constants directly in the file instead of importing them, the error goes away and works like expected
The text was updated successfully, but these errors were encountered: