Material-UI 4.8.1 API change - new way to specify the `component` property?

久未见 提交于 2021-02-19 06:49:05

问题


Edit: This was a bug in the typing of 4.8.x, upgrade to 4.9.0+ to fix the issue.


On version 4.8.0, the following code compiles and runs fine:

      <DialogContent>
        {/* use a span so we can nest div, p, etc. */}
        <DialogContentText component="span">
          {confirmContent}
        </DialogContentText>
      </DialogContent>

After upgrading to 4.8.1 the code now fails type-checking with:

No overload matches this call.
  Overload 1 of 2, '(props: DialogContentTextProps, context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, a
ny, any>)> | null) | (new (props: any) => Component<...>)> | Component<...> | null', gave the following error.
    Type '{ children: Element; component: string; }' is not assignable to type 'IntrinsicAttributes & DialogContentTextProps'.
      Property 'component' does not exist on type 'IntrinsicAttributes & DialogContentTextProps'.
  Overload 2 of 2, '(props: PropsWithChildren<DialogContentTextProps>, context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any)
=> Component<...>)> | null) | (new (props: any) => Component<...>)> | Component<...> | null', gave the following error.
    Type '{ children: Element; component: string; }' is not assignable to type 'IntrinsicAttributes & DialogContentTextProps & { children?: ReactNode; }'.
      Property 'component' does not exist on type 'IntrinsicAttributes & DialogContentTextProps & { children?: ReactNode; }'.  TS2769

I can get my project compiling again by deleting the component="span" part - but what's the proper fix?

What's the new way to specify way to specify the base component used by DialogContentText?

My project is a standard create-react-app setup, using Typescript 3.7.4.


回答1:


This is a bug with the typings in material-ui, see: https://github.com/mui-org/material-ui/issues/19068

Fixed in 4.9.0



来源:https://stackoverflow.com/questions/59494907/material-ui-4-8-1-api-change-new-way-to-specify-the-component-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!