【发布时间】:2021-10-24 05:18:50
【问题描述】:
我正在尝试在 React 应用中使用基于 sx prop 的样式。°
我想通过所谓的theme getter 访问主题。
当我尝试使用这种方法时,我可以看到样式在浏览器中呈现正常。然而 TypeScript 抱怨,我发现理解类型血统并弄清楚它在说什么具有挑战性。
Working沙盒
完全错误:
No overload matches this call.
Overload 2 of 2, '(props: DefaultComponentProps<BoxTypeMap<{}, "div">>): Element', gave the following error.
Type 'string' is not assignable to type 'SystemStyleObject<Theme>'.
Overload 2 of 2, '(props: DefaultComponentProps<BoxTypeMap<{}, "div">>): Element', gave the following error.
Type '(theme: any) => { border: string; }' is not assignable to type 'SystemStyleObject<Theme>'.
Type '(theme: any) => { border: string; }' is not assignable to type 'CSSSelectorObject<Theme>'.ts(2769)
app.tsx(8, 22): Did you mean to call this expression?
大概我应该通过显式设置SystemStyleObject,但不确定从哪里导入它。任何指针将不胜感激。
° 应用使用 TypeScript 4.4.1-rc + MUI 5.0.0-beta.4
【问题讨论】:
标签: reactjs typescript material-ui emotion