-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in type annotation of NumberFormatBaseProps (NumberFormatBase) #740
Comments
UPVOTE |
Yes, make sense. Will fix the annotation here. |
This is fixed on v5.2.0 |
This produces a breaking change in typescript for the useNumericFormat hook Consider:
This update causes these newly optional properties to be returned as FormatInputValueFunction | undefined, so typescript will now complain with |
Facing the same issue
|
Describe the issue and the actual behavior
NumberFormatBase
component's props have following type annotation:As you can see,
format
,removeFormatting
andgetCaretBoundary
props are defined as required props.But in implementation of
NumberFormatBase
component we can see, that these props are optional, because they have default value:Because
format
,removeFormatting
andgetCaretBoundary
props are defined as required, I have following TS error*, when I try to useNumberFormatBase
component with only one set prop -format
:*TS error -
Type '{ valueIsNumericString: true; value: string; onValueChange: (values: NumberFormatValues) => void; format: (phoneNumber: string) => string; }' is missing the following properties from type 'NumberFormatBase': removeFormatting, getCaretBoundary ts(2739)
I set only
format
prop, because I need only custom formatting in my case. But TS expectsremoveFormatting
andgetCaretBoundary
will be set too. Despite the fact, thatremoveFormatting
andgetCaretBoundary
props are missing, component works ok, becauseNumberFormatBase
component has default values for these props.Describe the expected behavior
I see 2 possible solutions:
format
,removeFormatting
andgetCaretBoundary
props are defined as optional props in type annotation:react-number-format
for some reason needsformat
,removeFormatting
andgetCaretBoundary
props to be required, default values of these props should be exported too, to be used where lib users need default behavior:Provide a CodeSandbox link illustrating the issue
Modified demo from your docs - https://codesandbox.io/s/card-expiry-field-forked-8ex966?file=/src/App.tsx
The text was updated successfully, but these errors were encountered: