Typescript和Redux:绑定元素“字符串”隐式具有“任意”类型

RuntimeError

在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因此,我宣布它stringProps了。我认为这是绝对正确的。请注意:执行reduxAction: ({value: any}) => void;操作时,会出现与相同的错误anyBinding element 'any' implicitly has an 'any' type

您能告诉我我在做什么错吗?

RuntimeError

如果有人为这个问题而苦苦挣扎:

您必须使用操作中声明的类型在函数中声明变量的类型。

reduxAction: (value: reduxActionState) => void;

...因为actions.ts我宣布

export const reduxAction = (value: reduxActionState): ResultValueType => ({
  type: SET_RESULT_VALUE,
  payload: value,
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

绑定元素“字符串”隐式具有“任意”类型

元素隐式具有“任意”类型,因为类型“字符串”的表达式不能用于索引类型A

元素隐式具有“任意”类型,因为类型“字符串”的表达式不能用于索引

绑定元素“索引”隐式具有“任意”类型

绑定元素“导航器”隐式具有“任意”类型

元素隐式具有“任何”类型,因为“字符串”类型的表达式

TypeScript:元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型

绑定元素“输入”隐式具有 redux 形式的“任何”类型

带有 Rest Operator 绑定元素 x 的 TypeScript 隐式具有“任何”类型

React Typescript - 绑定元素“C”隐式具有“任何”类型。TS7031

Graphql React Typescript 错误绑定元素“货币”隐式具有“任何”类型

绑定元素'Component'隐式具有'any'类型.ts

绑定元素“ title”隐式具有“ any”类型

绑定元素“posts”隐式具有“any”类型

元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引“类型”类型

元素隐式具有 'any' 类型,因为类型 'string' 的表达式不能用于索引类型 {"1" : { "key": string}; "2" : { "key": 字符串};}

反应打字稿错误 - 元素隐式具有任何类型,因为类型字符串的表达式不能用于索引类型 {}

Angular - 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型

如何修复元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型?

TS7053:元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引“User_Economy”类型

错误 TS7053:元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引“模块类型”

元素隐式地具有“ any”类型,因为在打字稿中将字符串转换为enum时,索引表达式不是enum的“ number”类型

为什么我在这里使用 TypeScript 得到“绑定元素‘商店’隐式具有‘任何’类型”?

React Typescript:元素隐式地具有“ any”类型,因为类型没有索引签名

React Navigation 5错误绑定元素'navigation'隐式具有'any'类型.ts

绑定元素“ dispatch”隐式具有“ any”类型。var dispatch:任何

Nuxt-asyncData错误:“绑定元素'$ axios'隐式具有'any'类型。”

打字稿:参数“错误”隐式具有“任意”类型

具有上下文绑定的类型类隐式