-
Notifications
You must be signed in to change notification settings - Fork 418
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
Pass custom attributes and props #508
Comments
The ref issue should be fixable, as we extend input the ref type is wrongly set. Will fix the ref issue. For types of other custom props, need to explore a little. |
Ohh, checked. Actually, this is not an issue. NumberFormat is a component, and inputRef is of type HTMLInputElement, which is why it throws an error. Please refer. https://github.com/s-yadav/react-number-format/blob/master/README.md#getting-reference Let if know if this doesn't fix the issue. |
@s-yadav is it possible to pass all props into NumberFormat component by using <NumberFormat
thousandSeparator={true}
decimalScale={2}
allowNegative={false}
inputmode="numeric"
// this generates the error:
{...props}
/> 13:18:08 webpack.1 | ERROR in app/demo.js
13:18:08 webpack.1 | TS2769: No overload matches this call.
13:18:08 webpack.1 | Overload 1 of 2, '(props: NumberFormatProps | Readonly<NumberFormatProps>): NumberFormat', gave the following error.
13:18:08 webpack.1 | Type '{ accept?: string | undefined; alt?: string | undefined; autoComplete: string | undefined; autoFocus?: boolean | undefined; capture?: string | boolean | undefined; checked?: boolean | undefined; ... 286 more ...; value: (string & (string | ... 1 more ... | readonly string[])) | undefined; }' is not assignable to type 'Readonly<NumberFormatProps>'.
13:18:08 webpack.1 | Types of property 'defaultValue' are incompatible.
13:18:08 webpack.1 | Type 'string | number | readonly string[] | undefined' is not assignable to type 'string | number | undefined'.
13:18:08 webpack.1 | Type 'readonly string[]' is not assignable to type 'string | number | undefined'.
13:18:08 webpack.1 | Type 'readonly string[]' is not assignable to type 'string'.
13:18:08 webpack.1 | Overload 2 of 2, '(props: NumberFormatProps, context: any): NumberFormat', gave the following error.
13:18:08 webpack.1 | Type '{ accept?: string | undefined; alt?: string | undefined; autoComplete: string | undefined; autoFocus?: boolean | undefined; capture?: string | boolean | undefined; checked?: boolean | undefined; ... 286 more ...; value: (string & (string | ... 1 more ... | readonly string[])) | undefined; }' is not assignable to type 'Readonly<NumberFormatProps>'.
13:18:08 webpack.1 | Types of property 'defaultValue' are incompatible.
13:18:08 webpack.1 | Type 'string | number | readonly string[] | undefined' is not assignable to type 'string | number | undefined'.
13:18:08 webpack.1 | 19 | } & React.InputHTMLAttributes<HTMLInputElement>) => {
13:18:08 webpack.1 | 20 | return (
13:18:08 webpack.1 | > 21 | <NumberFormat
13:18:08 webpack.1 | | ^^^^^^^^^^^^
13:18:08 webpack.1 | 22 | thousandSeparator={true}
13:18:08 webpack.1 | 23 | decimalScale={2}
13:18:08 webpack.1 | 24 | allowNegative={false}
13:18:08 webpack.1 | ℹ 「wdm」: Failed to compile. Right now I'm forced to pass them one by one: <NumberFormat
thousandSeparator={true}
decimalScale={2}
allowNegative={false}
inputmode="numeric"
// now this works fine
demoProp={props.demoProp}
onChange={() => props.onChange()}
value={props.value.toString()}
/> |
From the error it looks like the type coming in props for defaultValue is different from what defined in NumberFormat. We have a custom type for defaultValue. and |
There is one PR related to this which will allow |
Yeah, but what I found strange is that I was not sending the I managed to make it work by filtering defaultValue and value from the props. <PriceInput
inputRef={inputRef}
id="my_id"
value={value}
onChange={(e) => {
//...
}}
maxLength={10}
placeholder={5}
disabled={false}
autoComplete="off"
/> export const PriceInput = ({
inputRef,
value,
defaultValue,
...props
}: {
value?: string;
defaultValue?: string;
} & React.InputHTMLAttributes<HTMLInputElement>) => {
return (
<NumberFormat
thousandSeparator={true}
decimalScale={2}
allowNegative={false}
inputMode="numeric"
customInput={CustomInput}
value={value}
{...props}
/>
);
}; |
I think this was because of how typescript infers the props object. If value and defaultValue is not filtered, it will try to match complete But when we extract it out, now typescript knows props is excluding defaultValue and value. |
I see, thanks! |
I have the same issue with Bootstrap FormControl
|
I'm trying to add the
ref
attribute with theinputRef
value:I've read other issues such as #295 but I don't think any solves this problem so far?
I'm getting the following error:
So far, and following this other issue #422 the only way to fix it seems to be by adding
// @ts-ignore
.Any better workaround?
The text was updated successfully, but these errors were encountered: