संपादित में स्थिरांक का उपयोग कर "शाब्दिक जो मामले को चुनने के लिए तय नहीं कर सका वस्तु"।flowtype: एक न्यूनतम उदाहरण है कि इस मुद्दे को पता चलता की <a href="https://github.com/saadq/test-ignore" rel="noreferrer">Here is a full GitHub repo</a>: जब redux कार्यों
मेरे पास एक साधारण काउंटर ऐप है। यहाँ मेरी कार्रवाई रचनाकारों हैं:
actions.js
/**
* @flow
*/
import { INCREMENT, DECREMENT } from '../constants'
type Action =
| { type: 'INCREMENT' }
| { type: 'DECREMENT' }
function increment(): Action {
return {
type: INCREMENT
}
}
function decrement(): Action {
return {
type: DECREMENT
}
}
export { increment, decrement }
export type { Action }
वर्तमान में, मैं दोनों increment
और decrement
कार्यों में कोई त्रुटि है जिसमें कहा गया है कि वस्तु शाब्दिक जो मामले को चुनने के लिए तय नहीं किया जा सका हो रही है संघ प्रकार।
इन त्रुटियों को ठीक करने के लिए, मैं type: 'INCREMENT'
को type: INCREMENT
बदल सकते हैं और type: 'DECREMENT'
को type: DECREMENT
बदल सकते हैं। हालांकि, मैं इस स्थिरता का उपयोग कई स्थानों (रेड्यूसर की तरह) में करने जा रहा हूं, इसलिए मैं केवल स्थिर आयात करने और वहां इसका उपयोग करने में सक्षम होने की उम्मीद कर रहा था। क्या यह फ्लो टाइप में ऐसा नहीं है?
constants.js
/**
* @flow
*/
const INCREMENT: 'INCREMENT' = 'INCREMENT'
const DECREMENT: 'DECREMENT' = 'DECREMENT'
export {
INCREMENT,
DECREMENT
}
reducer.js
/**
* @flow
*/
import { INCREMENT, DECREMENT } from '../constants'
import type { Action } from '../actions'
type State = number
function counter(state: State = 0, action: Action): State {
switch (action.type) {
case INCREMENT:
return state + 1
case DECREMENT:
return state - 1
default:
return state
}
}
export default counter
संपादित करें::
स्पष्टता के लिए, यहां फ़ाइलों के बाकी हैं यहाँ एक विस्तृत त्रुटि है लॉग
src/actions/counter.js:12
v
12: return {
13: type: INCREMENT
14: }
^object literal. Could not decide which case to select
11: function increment(): Action {
^^^^^^ union type
Case 1 may work:
8: | { type: 'INCREMENT' }
^^^^^^^^^^^^^^^^^^^^^ object type
But if it doesn't, case 2 looks promising too:
9: | { type: 'DECREMENT' }
^^^^^^^^^^^^^^^^^^^^^ object type
Please provide additional annotation(s) to determine whether case 1 works (or consider merging it with case 2):
13: type: INCREMENT
^^^^^^^^^ identifier `INCREMENT`
src/actions/counter.js:18
v
18: return {
19: type: DECREMENT
20: }
^object literal. Could not decide which case to select
17: function decrement(): Action {
^^^^^^ union type
Case 1 may work:
8: | { type: 'INCREMENT' }
^^^^^^^^^^^^^^^^^^^^^ object type
But if it doesn't, case 2 looks promising too:
9: | { type: 'DECREMENT' }
^^^^^^^^^^^^^^^^^^^^^ object type
Please provide additional annotation(s) to determine whether case 1 works (or consider merging it with case 2):
19: type: DECREMENT
^^^^^^^^^ identifier `DECREMENT`
प्रत्येक काउंटर से निरंतर अलग-अलग निर्यात करें: 'निर्यात कॉन्स INCREMENT =' INCREMENT''। और उन्हें अपने action.js में फिर से निर्यात करना जरूरी नहीं है। – FrenchMajesty
यह समस्या को हल करने के लिए प्रतीत नहीं होता है, लेकिन यह क्यों होगा? निर्यात करने की विधि और आपके द्वारा उल्लिखित विधि दोनों मॉड्यूल से चीजों को निर्यात करने के वैध तरीके हैं। उन्हें पुनः निर्यात करने के बारे में आपकी टिप्पणी के लिए, मुझे नहीं लगता कि मैं हूं। मैं सिर्फ एक्शन निर्माता को निर्यात कर रहा हूं। – saadq
आप कहते हैं कि 'इन स्थिरांकों में प्रकार जोड़ने की कोशिश की गई', आपने विशेष रूप से क्या प्रयास किया? मुझे लगता है कि आपको 'कॉन्स इंक्रेमेंट' की आवश्यकता होगी: 'वृद्धि' = 'वृद्धि'। – loganfsmyth