| I recently created a new NextJS project. For my little site I needed an input element with type=file. So I was getting started, with TypeScript and all, like the swaggest of web developers. Came the moment for the actual file input: TypeScript REFUSED to accept the input element's type as "HTMLInputElement" when that is literally its type. After TypeScript eating up about 1 hour or so of my time, I decided to get rid of that piece of sh*t for squiggly underlining all my code in Red simply because it's too retarded to understand it. Any of the TypeScript lovers care to explain? Needless to say, I ultimately went about doing what I wanted in 5 minutes in VanillaJS and was happy ever after. Call me again when TypeScript does its job correctly. |
As to your problem: Use ˋ... as HTMLInputElementˋ if Typescript wasn't able to narrow your type sufficiently, or you believe that the value of typing this case isn't worth the effort. This should be somewhat rare.
Use ˋ... as unknown as HTMLInputElementˋ, if your idea of the variable is completely different from Typescript. But at that point you likely _have_ made a mistake somewhere.
Use ˋ...: anyˋ if you want to completely turn off checking. In most projects, this has to be explicitly specified for each parameter and declaration.
It gets more verbose, the more unsafe your code is.