-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
Description
Hello,
I am having a problem when creating unions that use typeof to determine the type of imported variables. So, for example, the following doesn't work:
Example that doesn't work
constants.js
export const PRODUCT_SET_ID: 'PRODUCT_SET_ID' = "PRODUCT_SET_ID"
export const PRODUCT_RESET: 'PRODUCT_RESET' = "PRODUCT_RESET"actions.js
import {
PRODUCT_SET_ID,
PRODUCT_RESET
} from './constants'
export type Action =
{| type: typeof PRODUCT_SET_ID, id: number |} |
{| type: typeof PRODUCT_RESET, id: number |}
export const productSetId = (id: number) : Action => ({
type: PRODUCT_SET_ID,
id,
})This returns the error object literal Could not decide which case to select union type Case 1 may work: exact type: object type But if it doesn't, case 2 looks promising too: exact type: object type Please provide additional annotation(s) to determine whether case 1 works (or consider merging it with case 2): identifier 'PRODUCT_SET_ID'
Works without import
If I substitute the imports for inline declarations, the whole example works.
actions.js
export const PRODUCT_SET_ID: 'PRODUCT_SET_ID' = "PRODUCT_SET_ID"
export const PRODUCT_RESET: 'PRODUCT_RESET' = "PRODUCT_RESET"
export type Action =
{| type: typeof PRODUCT_SET_ID, id: number |} |
{| type: typeof PRODUCT_RESET, id: number |}
export const productSetId = (id: number) : Action => ({
type: PRODUCT_SET_ID,
id,
})I don't think this should happen, as it makes it harder to separate code into modular files. Any solutions or workarounds to continue using import?
Reactions are currently unavailable