typescript - 排版组件
问题描述
根据这里的材料 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>
这对我来说仍然是一个障碍。
鉴于我给出的第一个示例与文档完全匹配,我不知道如何推进该主题。
解决方案
component={'div' as any}
就隐藏打字稿错误而言,使用对我有用。
推荐阅读
- powerquery - Power Query M - 按索引选择列
- python - Python:KeyError,但键和值都存在
- c++ - 触发 KeyDown 时发出蜂鸣声
- c# - 如何避免在编辑字段时未触发 PropertyChanged 事件
- php - laravel 搜索作者
- javascript - 如何在javascript中将多个数组合并为单个数组
- html - 在 html 文档的每个打印页面上重复页眉和页脚?每页也应该有一个边框
- wordpress - Yoast SEO如何允许爬虫机器人
- java - 使用私有静态最终 Logger logger = Logger.getLogger(Reports.class); 在控制台上打印日志但没有创建文件
- c# - Protobuf.net - 需要序列化的类的所有字段