D
D
DeniSidorenko2021-03-15 08:21:19
typescript
DeniSidorenko, 2021-03-15 08:21:19

Why doesn't it throw an error with this typing?

hello there is this function

const onChangeHandler = (e:React.FormEvent<HTMLInputElement>) => {
    console.log(e.currentTarget)
}

Where is it specified that HTMLInputElement is expected, but even if I apply this function to the header, div , any element, it still works without errors?

For example, there are no errors

<div className="title" onChange={onChangeHandler}>
                    <h2>Добавить категорию</h2>
                </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VitalyChaikin, 2021-03-15
@VitalyChaikin

(e:React.FormEvent<HTMLInputElement>) означает на мой взгляд:
e:React.FormEvent <типа HTMLInputElement>
СобытиеFormEvent<От любого HTMLInputElement>
Подозреваю что div является HTMLInputElement -ом

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question