Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

Getting "No overload matches this call" error while converting code to TypeScript

I'm new with TypeScript, I have converted all my code (React Hooks) into TypeScript except for this one thing where I get the following error:

No overload matches this call.

  Overload 1 of 2, '(props: { component: ElementType; } & { children?: ReactNode; color?: "primary" | "secondary" | undefined; disabled?: boolean | undefined; error?: boolean | undefined; ... 6 more ...; variant?: "outlined" | ... 2 more ... | undefined; } & CommonProps & Pick): Element', gave the following error.
    Property 'component' is missing in type '{ children: Element; className: string; htmlFor: string; }' but required in type '{ component: ElementType; }'.
  Overload 2 of 2, '(props: DefaultComponentProps>): Element', gave the following error.
    Type '{ children: Element; className: string; htmlFor: string; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; color?

The issue is coming from here:

import {
  Box,
  Button,
  TextField,
  FormControl,
  FormGroup,
  Select,
} from "@material-ui/core/";
import { Trans } from "react-i18next";

interface ConnectedLinkProps {
  onSubmit: string;
  classes: {
    formControl: string;
  };
}


<FormControl className={classes.formControl} htmlFor="source">
  <TextField
    id="source"
    disabled={true}
    value={linkSettings.source}
    label={<Trans i18nKey="form.linkForm.sourceNode">Source Node</Trans>}
  />
</FormControl>;

The whole first line which is 'FormControl line' is red.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The error should go away if you remove the props from the FormControl component.

<FormControl>
  <TextField
    id="source"
    disabled={true}
    value="Something"
    label={<Trans i18nKey="form.linkForm.sourceNode">Source Node</Trans>}
  />
</FormControl>

The FormControl component doesn't support the className or htmlFor prop.

Link to a forked example on CodeSandbox.

The working example of the shared code will be something like this:

import React from "react";
import {
  Box,
  Button,
  TextField,
  FormControl,
  FormGroup,
  Select,
  InputLabel
} from "@material-ui/core/";
import { Trans } from "react-i18next";

interface ConnectedLinkProps {
  onSubmit: string;
  classes: {
    formControl: string;
  };
}

const App: React.FC<ConnectedLinkProps> = ({ onSubmit, classes }) => {
  return (
    <div className="App">
      <FormControl>
        <InputLabel htmlFor="source">Something</InputLabel>
        <TextField
          id="source"
          disabled={true}
          value="Something"
          label={<Trans i18nKey="form.linkForm.sourceNode">Source Node</Trans>}
          className={classes?.formControl}
        />
      </FormControl>
    </div>
  );
};

export default App;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...