类型“ B”缺少属性“ A”,但类型“ C”必需

时间:2019-12-01 17:53:14

标签: typescript types material-ui react-admin

我对Typescript还是很陌生,遇到了一个我不太了解的错误。我设法解决了这个问题(我认为),但我只是很好奇能真正理解错误的含义。

这是错误:

TypeScript error in /home/js/Development/gigalixir-web/src/RegisterPage.tsx(155,42):
Argument of type 'typeof Login' is not assignable to parameter of type 'AnyComponent<Pick<StyledComponentProps<"main" | "avatar" | "icon" | "card"> & Partial<WithTheme>, "theme"> & Partial<WithTheme> & { classes: Record<"main" | "avatar" | "icon" | "card", string>; }>'.
  Type 'typeof Login' is not assignable to type 'new (props: Pick<StyledComponentProps<"main" | "avatar" | "icon" | "card"> & Partial<WithTheme>, "theme"> & Partial<WithTheme> & { classes: Record<"main" | "avatar" | "icon" | "card", string>; }) => Component<...>'.
    Types of parameters 'props' and 'props' are incompatible.
      Property 'loginForm' is missing in type 'Pick<StyledComponentProps<"main" | "avatar" | "icon" | "card"> & Partial<WithTheme>, "theme"> & Partial<WithTheme> & { classes: Record<"main" | "avatar" | "icon" | "card", string>; }' but required in type 'Readonly<Props & Partial<WithTheme> & { classes: Record<"main" | "avatar" | "icon" | "card", string>; } & HtmlHTMLAttributes<HTMLDivElement>>'.  TS2345

    153 | }
    154 | 
  > 155 | const EnhancedLogin = withStyles(styles)(Login) as ComponentType<Props>
        |                                          ^
    156 | 
    157 | // EnhancedLogin.propTypes = {
    158 | //   backgroundImage: PropTypes.string,

来自this file的人。

我通过将this line上的object更改为与this line匹配的Theme来解决了,或者至少是这样。这些类型应该匹配对我来说很有意义,但是我想我的问题是

  1. 当错误与loginForm有关时,为什么上面的错误提到theme
  2. 为什么here不会发生错误,我从那里复制并粘贴了此代码。

谢谢!任何帮助表示赞赏!

0 个答案:

没有答案