Avatar ·

Typing React Events in TypeScript: How to Properly Specify Types for Handlers?

Hello everyone! I've just started learning TypeScript with React and ran into a problem — I can't figure out how to properly type events. The React documentation on TypeScript mentions many different types, but I'm confused about which one to use for each situation.\n\nHere's a simple example: I have a form with an input, and I want to handle the onChange event. In JavaScript I would just write:\n\n```tsx\nfunction handleChange(e) {\n setValue(e.target.value);\n}\n```\n\nBut in TypeScript this gives an error: "Parameter 'e' implicitly has an 'any' type". I tried writing `React.ChangeEvent`, but I'm not sure if that's correct. What about the form's onSubmit? Or a button's onClick? Is there a universal type for all events?\n\nAnother question: how do you type custom events or events that come