简体   繁体   English

(参数)e:React typescript 中的任何错误

[英](parameter) e:any error in React typescript

1

The error says (parameter)e:any and doesn't compile, I tried changing it to ('submit', e:any) but that didn't work either, and says错误说(parameter)e:any并且无法编译,我尝试将其更改为('submit', e:any)但这也不起作用,并说

any refers to a type, but it is being used as a value here. any 指的是一种类型,但在这里它被用作一个值。

How do I simply pass e into addEventListener ?我如何简单地将e传递给addEventListener

You should have included a full example of what you're trying, but judging by your description, you're probably setting the type of e incorrectly.您应该包含您正在尝试的完整示例,但从您的描述来看,您可能错误地设置了e的类型。 Try this:尝试这个:

form2.addEventListener('submit', (e: any) => {
  // your function here
});

It looks like you're trying看起来你正在尝试

form2.addEventListener('submit', e:any) =>

In that case, please keep in mind that addEventListener takes two parameters in this case:在这种情况下,请记住addEventListener在这种情况下需要两个参数:

  • the event type ( submit ),事件类型( submit ),
  • and a function ( e => {... } ).和一个 function ( e => {... } )。 So you must set the parameter in said function so it becomes ( (e: any) => {...} ), and that's how we arrive to the aforementioned solution.因此,您必须在所述 function 中设置参数,使其变为 ( (e: any) => {...} ),这就是我们到达上述解决方案的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Typescript:'{ [x: number]: any; 类型的参数 }' 不可分配给类型的参数 - React Typescript: Argument of type '{ [x: number]: any; }' is not assignable to parameter of type Typescript 任意 | 任何[] 作为 function 参数 - Typescript any | any[] as function parameter TypeScript 错误参数“props”隐式具有“any”类型 - TypeScript error Parameter 'props' implicitly has an 'any' type React 组件上的 Typescript 错误:“元素”类型的参数不可分配给类型的参数 - Typescript error on React Component: Argument of type 'Element' is not assignable to parameter of type 反应路由器 6.4.3 typescript - useLocation 任何类型错误 - react router 6.4.3 typescript - useLocation any type error React typescript 错误:元素隐式具有“任何”类型 - React typescript error: Element implicitly has an 'any' type Typescript React 将参数传递给 setState - Typescript React Passing parameter to setState React Typescript不可分配给type参数 - React typescript is not assignable to parameter of type 如何在 React TypeScript 中实现 e 和 props? - How to implement e and props in React TypeScript? 收到 Typescript 错误,说某些类型不可分配给类型为“ReducerWithoutAction”的参数<any> &#39;? - Getting a Typescript error saying, some type is not assignable to parameter of type 'ReducerWithoutAction<any>'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM