'Is there a way to get Material-UI's textfield to return a number instead of a string when used with type="number"?

I am using Material-UI's TextField in conjunction with react-hook-form to watch inputs. I have noticed that regardless of the type of the input, a string is returned. This clashes with the types I use in the codebase.

I have read about different ways to handle this issue on react-hook-form's side, with transforming the returned data but I couldn't find anything about making TextField return a different type depending on how it's used. I'm especially surprised because as far as I understand, valueAsNumber exists natively on HTML inputs (https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source