Reactjs 如何在材质ui中的样式化组件中指定其他道具?
我有一个由Reactjs 如何在材质ui中的样式化组件中指定其他道具?,reactjs,typescript,material-ui,Reactjs,Typescript,Material Ui,我有一个由材质ui中的和样式定义的样式化组件。我正在使用typescript,所以它在最后一行抱怨类型错误。原因是组件ServiceListComponent需要classes和services,但withStyles只提供classes。服务将由父组件提供。如何使with style语句中的类型正确 const styles = createStyles({...}) interface Props { services: RootState.ServicesState; classe
材质ui
中的和样式定义的样式化组件。我正在使用typescript
,所以它在最后一行抱怨类型错误。原因是组件ServiceListComponent
需要classes
和services
,但withStyles
只提供classes
。服务将由父组件提供。如何使with style
语句中的类型正确
const styles = createStyles({...})
interface Props {
services: RootState.ServicesState;
classes: { [className in keyof typeof styles]: string };
}
const ServiceListComponent = ({ classes, services }: Props) => {
return (
<Grid container className={classes.root}>
<Grid container className={classes.parent} spacing={8}>
{itemsArray.map(value => (
<Grid key={value} item className={classes.item} xs={4} sm={4} md={3} xl={4}>
<Paper className={classes.paper} />
</Grid>
))}
</Grid>
</Grid>
);
};
ServiceListComponent.propTypes = {
classes: PropTypes.object.isRequired,
};
export const ServiceList = withStyles(styles)(ServiceListComponent);
TS2345: Argument of type '{ ({ classes, services }: Props): Element; propTypes: { classes: Validator<object>; }; }' is not assignable to parameter of type 'ComponentType<ConsistentWith<Props, { classes: Record<"root" | "parent" | "paper" | "items" | "item", string>; }>>'.
Type '{ ({ classes, services }: Props): Element; propTypes: { classes: Validator<object>; }; }' is not assignable to type 'FunctionComponent<ConsistentWith<Props, { classes: Record<"root" | "parent" | "paper" | "items" | "item", string>; }>>'.
Types of property 'propTypes' are incompatible.
Type '{ classes: Validator<object>; }' is not assignable to type 'WeakValidationMap<ConsistentWith<Props, { classes: Record<"root" | "parent" | "paper" | "items" | "item", string>; }>>'.
Types of property 'classes' are incompatible.
Type 'Validator<object>' is not assignable to type 'Validator<{ root: string; parent: string; paper: string; items: string; item: string; }>'.
Type '{}' is missing the following properties from type '{ root: string; parent: string; paper: string; items: string; item: string; }': root, parent, paper, items, item
export const ServiceList = withStyles(styles)<any>(ServiceListComponent);