Essential Types And Notations 20 exercises
Problem

The Controversial `any` Type

Moving on, let's take a look at any, a controversial but useful type in TypeScript.

We have a function called handleFormData that accepts an e typed as any. The function prevents the default form submission behavior, then creates an object from the form data and returns it:


const h

Loading exercise

Transcript

00:00 In this exercise, we're going to look at any. A very famous, very useful, but very controversial type in TypeScript. We have a handleFormData function at the top. We're calling e.preventDefault to prevent anything default happening with that form. We're creating some form data out of that form,

00:19 and then we're basically saying creating an object from that form data and returning that object. In our tests, we have a document.createElement form. We set that in a HTML to add an input. Then we manually submit the form, and when it submits, we expect the value to equal the value that was in our form

00:38 that we sort of grafted in there. So this isn't the normal way that you test forms, but I wanted to do this to basically really test out our handleFormData, and something's gone wrong. There is an error in this setup somewhere, but we don't quite know where. So your job is going to be to take a look at this,

00:56 see if you can figure out why this error is happening, and debug it. And while you're at it, see if you can figure out what this any is doing for us, if anything.