useState
hook can infer the type. In fact:useState
is initialized with the string Fabio
.name
to be string
based on the initial value provided.name
is inferred to always be a string
, and setName
is expected to be called with a value of type string
.number
or a boolean
to the name
state, we get an error, although we did not explicitly the state to be typed as a string
:number
or a boolean
to the name
"state" we get an error, even though we did not explicitly specify that the state should be typed as a string.useState
is initialized with null
or undefined
since he would not be able to deduce the type