const input: HTMLElement = e.target
const validity: ValidityState = input.validity
setValidity(validity.valid)
I'm just getting into typescript and having a problem with the ValidityState API: the second line gets a red squiggly underline with Unsafe assignment of an 'any' value
.
What's the proper course of action here?
Top comments (3)
HTMLElement
does not havereadonly validity: ValidityState
property. Only the following elements have that property.github.com/microsoft/TypeScript/bl...
If you are using React, you can write as follows:
TS playground link
or
Or if you wanted to define a handler function, you can write as follows:
or
Thanks a bunch! It helped a lot.