在Android的React Native应用程序中,我有一个使用的组件Redux
。
如该线程中“ Hemant”所述,我也必须传递导入props
到组件中的动作。现在,我尝试正确键入操作,但是它给了我错误:Binding element 'string' implicitly has an 'any' type
而且我不明白为什么。
这是代码:
imports ...
import {reduxAction} from '../../../store/searchBar/actions';
type Props = {
reduxAction: ({value: string}) => void;
};
const SearchBar: React.FC<Props> = ({reduxAction}) => {
// calling the action method
const sendNamesToReduxStore = (names: string) => {
// ... some other logic
// calling the action method
reduxAction({value: names});
};
如您所见,调用action方法时,names
被声明为string
。因此,我宣布它string
在Props
了。我认为这是绝对正确的。请注意:执行reduxAction: ({value: any}) => void;
此操作时,会出现与相同的错误any
:Binding element 'any' implicitly has an 'any' type
。
您能告诉我我在做什么错吗?
如果有人为这个问题而苦苦挣扎:
您必须使用操作中声明的类型在函数中声明变量的类型。
reduxAction: (value: reduxActionState) => void;
...因为actions.ts
我宣布
export const reduxAction = (value: reduxActionState): ResultValueType => ({
type: SET_RESULT_VALUE,
payload: value,
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句