s-yadav / react-number-format

React component to format numbers in an input or as a text.
MIT License
3.85k stars 404 forks source link

TypeScript: react-number-format native `<input />` types mismatch React's `InputHTMLProps<HTMLInputElement>` #726

Open zachgoll opened 1 year ago

zachgoll commented 1 year ago

Describe the issue and the actual behavior

There seems to be a mismatch between react-number-format native input types and React's InputHTMLProps<HTMLInputElement>

image

When "spreading" the props to NumberFormat, the following type mismatches occur:

This can be worked around by explicitly casting the types:

image

Describe the expected behavior

I would expect that "spreading" InputHTMLProps<HTMLInputElement> to NumericFormat or PatternFormat would not cause any type errors. I suppose an argument could be made that type should be different given this library is specific to numbers, but I'm not seeing any reason why value and defaultValue should not match React's typings?

Provide a CodeSandbox link illustrating the issue

https://codesandbox.io/s/react-number-format-issues-726-3pvjt7

Provide steps to reproduce this issue

See CodeSandbox above.

Please check the browsers where the issue is seen

Not applicable. Type error.

fzhukov commented 1 year ago

same problem

fatihtanrivverdi commented 8 months ago

same problem

JavierLopezSCG commented 6 months ago

same problem x3 combo

sherman89 commented 4 months ago

+1 from me. This issue prevented us from using this library in our existing large codebase.