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

getInputRef type mismatch with using TextField material-ui. #220

Closed
IgnorantCoder opened this issue Sep 11, 2018 · 0 comments
Closed

getInputRef type mismatch with using TextField material-ui. #220

IgnorantCoder opened this issue Sep 11, 2018 · 0 comments

Comments

@IgnorantCoder
Copy link
Contributor

Hello.
I am using this module with material-ui.

I got the compile error in using it in TypeScript.
I found out type mismatch between getInputRef and inputRef that passed from material-ui.
I want to make type restriction of getInputRef lax for solving this problem.

Problem:

        <NumberFormat
            getInputRef={inputRef} 
            value={value as number}
            onValueChange={(values) => {
                if (onChange === undefined) {
                    return;
                }

                const event = {
                    target: {
                        value: values.value,
                    },
                } as React.ChangeEvent<HTMLInputElement>;
                onChange(event);
            }}
        />

error:

TS2326: Types of property 'getInputRef' are incompatible.
  Type 'string | ((instance: any) => any) | RefObject<any> | undefined' is not assignable to type '((el: HTMLInputElement) => void) | undefined'.
  Type 'string' is not assignable to type '((el: HTMLInputElement) => void) | undefined'.

Workarround:

        <NumberFormat
            getInputRef={inputRef as (el: HTMLInputElement) => void}
            value={value as number}
            onValueChange={(values) => {
                if (onChange === undefined) {
                    return;
                }

                const event = {
                    target: {
                        value: values.value,
                    },
                } as React.ChangeEvent<HTMLInputElement>;
                onChange(event);
            }}
        />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant