Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion typings/number_format.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Copy link
Owner

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.

Copy link
Author

@Magofoco Magofoco Nov 27, 2020

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

Screenshot 2020-11-27 at 22 06 15

Copy link
Owner

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.

isNumericString?: boolean;
customInput?: React.ComponentType<any>;
allowNegative?: boolean;
Expand Down