首页 > 解决方案 > 排版组件

问题描述

根据这里的材料 ui 文档:https ://material-ui.com/components/typography/

我应该能够使用 Typography 组件,如下所示:

<Typography variant="h1" component="h1">
  Hello World
</Typography>

然而,自从更新到 nextjs 9,我得到这个输入错误:

Type 'string' is not assignable to type 'ElementType<HTMLAttributes<HTMLElement>>'

对于组件属性。我已经尝试过更新输入依赖项,但似乎没有任何帮助。

感谢 Shanon 的建议,错误现在已经转移到:

48:36 Type '"h1"' is not assignable to type 'ElementType<HTMLAttributes<HTMLElement>>'.
    46 |         </Grid>
    47 |         <Grid item>
  > 48 |           <Typography variant="h1" component={'h1' as const}>
       |                                    ^
    49 |             Hello World
    50 |           </Typography>
    51 |         </Grid>

这对我来说仍然是一个障碍。

鉴于我给出的第一个示例与文档完全匹配,我不知道如何推进该主题。

标签: typescriptmaterial-uitypescript-typings

解决方案


component={'div' as any}就隐藏打字稿错误而言,使用对我有用。


推荐阅读