我正在使用带有打字稿的 MUI 并面临以下错误。我怀疑,我在这里遗漏了一种非常基本的东西,但无法抓住它。
Error: Type 'Color' is not assignable to type '"default" | "primary" | "secondary"'.
我在循环中使用芯片。 https://material-ui.com/components/chips/
这是沙箱:https://codesandbox.io/s/material-demo-forked-7g6cl?file=/demo.tsx
代码运行正常,但颜色下有错误。
答案 0 :(得分:1)
您的徽章类型具有类型 PropTypes.Color
,其中包含在芯片颜色道具类型中不存在的 inherit
关键字。
为了使类型兼容,您可以将其从类型中删除
badgeType: Exclude<PropTypes.Color, 'inherit'>