Closed alamenai closed 1 year ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
ai-code-translator | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Apr 4, 2023 11:36pm |
This is actually a mild dev preference.
I like being able to see "at a glance" the types even if they're inferred.
It's a visual thing.
In TypeScript, it is not mandatory to set types for all generics.
Though,
useState
is a generic function that takes a type argument to specify the type of the state variable.In this case, it's possible to remove the type annotation from the
useState
call because TypeScript can infer the type of the state variable based on the initial value. In this case, since the initial value is a string literal ('Copy'), TypeScript will infer that the type of the copyText state variable is a string.