Reactjs 从组件推断道具时缺少属性
因此,基本上,我发现自己在材质UI中经常使用这种模式,以避免使用内联样式或hook或hoc样式api:Reactjs 从组件推断道具时缺少属性,reactjs,typescript,material-ui,Reactjs,Typescript,Material Ui,因此,基本上,我发现自己在材质UI中经常使用这种模式,以避免使用内联样式或hook或hoc样式api: const TestStepper=styled(props=>( ))(({theme})=>({ 背景色:“透明”, “&>进度”:{ 宽度:“100%”, 边缘光:主题。间距(3) } })); 我不能依赖一个稳定的MuiMobileStepper progress类,所以我使用这个技巧来获得稳定的嵌套选择器 我想将这种行为封装在一个实用函数中: 导出函数styledNested< P
const TestStepper=styled(props=>(
))(({theme})=>({
背景色:“透明”,
“&>进度”:{
宽度:“100%”,
边缘光:主题。间距(3)
}
}));
我不能依赖一个稳定的MuiMobileStepper progress
类,所以我使用这个技巧来获得稳定的嵌套选择器
我想将这种行为封装在一个实用函数中:
导出函数styledNested<
P扩展了{classes:Record},
C扩展数组
>(组件:组件类型,…类别:C){
返回样式((道具:P)=>(
({…acc,[键]:键}),{}
/>
));
}
但在尝试时:
const TestStepper=styledNested(
手机设计师,
“进展”
)(({theme})=>({
背景色:“透明”,
“&>进度”:{
宽度:“100%”,
边缘光:主题。间距(3)
}
}));
我得到以下TS错误:
TS2345: Argument of type '(props: MobileStepperProps) => Element' is not assignable to parameter of type 'ComponentType<{ classes: Record<string, string>; }>'.
Type '(props: MobileStepperProps) => Element' is not assignable to type 'FunctionComponent<{ classes: Record<string, string>; }>'.
Types of parameters 'props' and 'props' are incompatible.
Type 'PropsWithChildren<{ classes: Record<string, string>; }>' is missing the following properties from type 'MobileStepperProps': backButton, nextButton, steps
TS2345:类型为“(props:MobileStepperProps)=>Element”的参数不能分配给类型为“ComponentType”的参数。
类型“(props:MobileStepperProps)=>元素”不可分配给类型“FunctionComponent”。
参数“props”和“props”的类型不兼容。
类型“PropsWithChildren”缺少类型“MobileStepperProps”中的以下属性:backButton、nextButton、steps
如何修复此问题?如果在编写
时在classes
prop中按住ctrl键并单击,是否可以将此作为代码沙盒链接发布?@dwjohnston