-
Notifications
You must be signed in to change notification settings - Fork 419
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
Added string[] and readonly string[] for NumberFormatProps for defaultValue #464
Added string[] and readonly string[] for NumberFormatProps for defaultValue #464
Conversation
Hey! Changelogs info seems to be missing or might be in incorrect format. |
@@ -39,7 +39,7 @@ declare module "react-number-format" { | |||
removeFormatting?: (formattedValue: string) => string; | |||
mask?: string | string[]; | |||
value?: number | string; | |||
defaultValue?: number | string; | |||
defaultValue?: number | string | string[] | readonly string[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But isn't this wrong.? defaultValue will never be array of string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@s-yadav
I was thinking the same, but apparently it can literally take any
.
See several examples here: https://codesandbox.io/s/awesome-benz-7vj06 with different defaultValue
types
For example, an array of string such as:
const myArray = ["First Element", "Second Element", "Third"]
if assigned to defaultValue
, will produce:
First Element, Second Element, Third Element
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can because of typecasting by JS. But that will still be wrong. Also, the type of value and default value should match.
Wrong typing can lead to confusion on dev end.
Is there any other way to force type in material ui.?
I guess the Material-UI has mentioned it as any because the Material UI supports the text field to be rendered as select.
This PR try to fix a type error of
NumberFormatProps
when using the MaterialUi TextfieldinputComponent
inInputProps
Failing example:
https://codesandbox.io/s/wonderful-chaplygin-f3otf
If you go to the component
MyInput
you can see that the componentNumberFormatCustom
takesNumberFormatProps
as props.The Material UI Textfied, in its
InputProps
, can take ainputComponent
which can be theNumberFormatCustom
component.This leads to a type error since the props Textfied's
defaultValue
types are:any
(https://material-ui.com/api/text-field/)while the NumberFormatProps's defaultValue is defined as:
string | number | undefined
.I tried to extend the types of
defaultValue
by includingstring[]
andreadonly string[]
which seem to solve the above mentioned error