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

The Select component cannot be used in TypeScript applications [Workaround Found] #5

Open
nemethmik opened this issue Jan 2, 2019 · 3 comments

Comments

@nemethmik
Copy link

nemethmik commented Jan 2, 2019

Type error: Type 'FunctionComponent' is not assignable to type 'string | ComponentClass<FieldRenderProps, any> | FunctionComponent | undefined'.
Type 'FunctionComponent' is not assignable to type 'FunctionComponent'.
Types of parameters 'props' and 'props' are incompatible.
Type 'FieldRenderProps & { children?: ReactNode; }' is not assignable to type 'FormHelperTextWrapperProps & { children?: ReactNode; }'.
Type 'FieldRenderProps & { children?: ReactNode; }' is missing the following properties from type 'FormHelperTextWrapperProps': label, formControlProps TS2322
141 | <div>
142 | <label>City </label>
143 | <Field name="city" label="Select city" component={FFMUI.Select}>
Up arrow pointing to the word component:
144 | <MenuItem value="London">London </MenuItem>
145 | <MenuItem value="Paris">Paris </MenuItem>
146 | </Field>

I've just found an easy workaround: type-cast the Select to any when assigned to the component prop:
component={FFMUI.Select as any}

@nemethmik nemethmik changed the title Select component cannot be used in TypeScript applications The Select component cannot be used in TypeScript applications Jan 2, 2019
@nemethmik nemethmik changed the title The Select component cannot be used in TypeScript applications The Select component cannot be used in TypeScript applications [Workaround Found] Jan 2, 2019
@karianpour
Copy link

I have a similar probelm :

TypeScript error: Type 'FunctionComponent<FormHelperTextWrapperProps>' is not assignable to type 'string | ComponentClass<FieldRenderProps<any>, any> | FunctionComponent<FieldRenderProps<any>> | undefined'.
  Type 'FunctionComponent<FormHelperTextWrapperProps>' is not assignable to type 'FunctionComponent<FieldRenderProps<any>>'.
    Types of parameters 'props' and 'props' are incompatible.
      Type 'PropsWithChildren<FieldRenderProps<any>>' is not assignable to type 'PropsWithChildren<FormHelperTextWrapperProps>'.
        Type 'FieldRenderProps<any> & { children?: ReactNode; }' is missing the following properties from type 'FormHelperTextWrapperProps': label, formControlProps  TS2322

    191 |                     fullWidth
    192 |                     name="city"
  > 193 |                     component={Select}
        |                     ^
    194 |                     label="Select a City"
    195 |                     formControlProps={{ fullWidth: true }}
    196 |                   >

package versions :

"react": "^16.8.4",
"@material-ui/core": "^3.9.2",
"final-form": "^4.12.0",
"typescript": "3.3.3333"
"react-final-form": "^4.1.0",
"final-form-material-ui": "^0.3.0",

alt the workaround above worked for me as well
component={Select as any}

I tried to fix the problem. I changed the Select.d.ts file as follow and the error is gone,

-interface FormHelperTextWrapperProps extends FieldRenderProps {
+interface FormHelperTextWrapperProps<T extends HTMLElement> extends FieldRenderProps<T> {

So tried to check if it is ok in the original file. I did the same in Select.tsx file and it gave me a new error, but there is same as the other files like TextField.tsx already has :

In TextField.tsx:
(alias) interface FieldRenderProps<T extends HTMLElement>
import FieldRenderProps
Generic type 'FieldRenderProps<T>' requires 1 type argument(s).ts(2314)

In edited Select.tsx
interface FormHelperTextWrapperProps<T extends HTMLElement>
Generic type 'FormHelperTextWrapperProps<T>' requires 1 type argument(s).ts(2314)

@nikonov91-dev
Copy link

Seems to be the Author doesnt want to add the solution to the project :(

@lookfirst
Copy link

Seems to be the Author doesnt want to add the solution to the project :(

@nikonov91-dev https://github.com/lookfirst/mui-rff

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

4 participants