diff --git a/src/guide/typescript-support.md b/src/guide/typescript-support.md index 53e2593f5c..550771f713 100644 --- a/src/guide/typescript-support.md +++ b/src/guide/typescript-support.md @@ -486,3 +486,36 @@ export default defineComponent({ } }) ``` + +### Typing Event Handlers + +When dealing with native DOM events, it might be useful to type the argument we pass to the handler correctly. Let's take a look at this example: + +```vue + + + +``` + +As you can see, without annotating the `evt` argument correctly, TypeScript will throw an error when we try to access the value of the `` element. The solution is to cast the event target with a correct type: + +```ts +const handleChange = (evt: Event) => { + console.log((evt.target as HTMLInputElement).value) +} +```