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

Ref is not defined on FormProp type #2135

Closed
jamazerto opened this issue Nov 19, 2020 · 14 comments · Fixed by #3267
Closed

Ref is not defined on FormProp type #2135

jamazerto opened this issue Nov 19, 2020 · 14 comments · Fixed by #3267

Comments

@jamazerto
Copy link

jamazerto commented Nov 19, 2020

Description

The following documentation example produces an error when compiling with typescript :
https://react-jsonschema-form.readthedocs.io/en/latest/advanced-customization/internals/#submit-form-programmatically

Steps to Reproduce

  1. Copy the example from https://react-jsonschema-form.readthedocs.io/en/latest/advanced-customization/internals/#submit-form-programmatically:
const onSubmit = ({formData}) => console.log("Data submitted: ",  formData);
let yourForm;

const schema = {
    type: "string"
};

render((
  <Form schema={schema}
        onSubmit={onSubmit} ref={(form) => {yourForm = form;}}/>
), document.getElementById("app"));

yourForm.submit();

Expected behavior

It should compile without problems

Actual behavior

When compiling with tsc

No overload matches this call.
  Overload 1 of 2, '(props: FormProps<any>, context?: any): ReactElement<any, any> | Component<FormProps<any>, any, any> | null', gave the following error.
    Type '{ children: Element; schema: JSONSchema7; liveValidate: true; noHtml5Validate: true; showErrorList: false; ref: (form: any) => void; onSubmit: (values: Record<string, any>)
e to type 'IntrinsicAttributes & FormProps<any>'.
      Property 'ref' does not exist on type 'IntrinsicAttributes & FormProps<any>'.
  Overload 2 of 2, '(props: PropsWithChildren<FormProps<any>>, context?: any): ReactElement<any, any> | Component<FormProps<any>, any, any> | null', gave the following error.
    Type '{ children: Element; schema: JSONSchema7; liveValidate: true; noHtml5Validate: true; showErrorList: false; ref: (form: any) => void; onSubmit: (values: Record<string, any>)
e to type 'IntrinsicAttributes & FormProps<any> & { children?: ReactNode; }'.
      Property 'ref' does not exist on type 'IntrinsicAttributes & FormProps<any> & { children?: ReactNode; }'.  TS2769

  > 47 |         ref={form => {
       |         ^
    48 |           yourForm = form;
    49 |         }}
    50 |         onSubmit={onSubmit}

Version

    "react": "^16.9.0",
    "typescript": "^3.8.3",
    "@rjsf/antd": "^2.4.0",
    "@rjsf/core": "^2.4.0",
    "@types/react": "^16.9.43",
@ievgennaida
Copy link

I have the same issue

@palenshus
Copy link

I was able to work around this for now by setting the id property on my Form, and then programmatically submitting with:

document.querySelector("#manifestForm") as any).requestSubmit()

@JoeryH
Copy link

JoeryH commented Mar 9, 2021

Goes without saying, but the workaround is disabling ts for that line:

// @ts-ignore
ref={}

@epicfaace
Copy link
Member

epicfaace commented Mar 9, 2021

Anyone interested in modifying index.d.ts to submit a fix? 🙏

@mattcosta7
Copy link
Contributor

I'm happy to work on the ts typings here, as it looks like there are a few that could be improved, but not entirely sure I can repro this as described

If anyone does have a repro, I'm happy to take a look. In my attempts to repro, I created these, which all appear to correctly work correctly?

https://codesandbox.io/s/brave-dan-6v243?file=/src/App.tsx

@mattcosta7
Copy link
Contributor

Spent a little more time trying to recreate this error here

https://codesandbox.io/s/trusting-wave-1kue3?file=/src/App.tsx

and am unable to

@jamazerto @ievgennaida can either of you send a minimal repro I can take a look at to help debug?

@JoeryH
Copy link

JoeryH commented Mar 15, 2021

Hi @mattcosta7, thanks for looking into this. I guess the author missed mentioning this, but we are using material-ui.
https://codesandbox.io/s/mystifying-cache-7jpqc?file=/src/App.tsx
Not sure if that works otherwise this is the main piece:

import Form from "@rjsf/material-ui";

@mattcosta7
Copy link
Contributor

mattcosta7 commented Mar 15, 2021 via email

@mattcosta7
Copy link
Contributor

mattcosta7 commented Mar 15, 2021 via email

@mattcosta7
Copy link
Contributor

mattcosta7 commented Mar 15, 2021 via email

@mattcosta7
Copy link
Contributor

@JoeryH thanks again for that repro and update.

Opened a PR for the typing updates here - feel free to make a similar change locally and report back if this works on your end as well.

// @rjsf/material-ui.   Form
import Form from '@rjsf/core'
const MuiForm: typeof Form = withTheme(them);

should make the ref (and the generic for formData) play much nicer

@ibrahimawadhamid
Copy link

@JoeryH thanks again for that repro and update.

Opened a PR for the typing updates here - feel free to make a similar change locally and report back if this works on your end as well.

// @rjsf/material-ui.   Form
import Form from '@rjsf/core'
const MuiForm: typeof Form = withTheme(them);

should make the ref (and the generic for formData) play much nicer

Is this going to be merged soon?

@heath-freenome
Copy link
Member

Now that core has been converted to Typescript this should be fixed in the v5 beta

@cdolek
Copy link

cdolek commented Nov 30, 2022

Now that core has been converted to Typescript this should be fixed in the v5 beta

for themed forms, can not set ref using beta.13 - any workarounds for this?

... is not assignable to type 'IntrinsicAttributes & FormProps<any, any>'.
Property 'ref' does not exist on type 'IntrinsicAttributes & FormProps<any, any>

@heath-freenome heath-freenome reopened this Dec 1, 2022
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Dec 1, 2022
Fixed rjsf-team#2135 by adding missing `ref` to `ThemeProps`
heath-freenome added a commit that referenced this issue Dec 3, 2022
Fixed #2135 by adding missing `ref` to `ThemeProps`
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants