发现了很多类似的问题,但没有什么能完全回答这个问题。您如何将两者都传递theme
给props
Material UImakeStyles
钩子,但又如何从最外层的闭包中访问它们而不会导致 TS 爆炸?像这样的东西:
type StyleProps = {
post: Post;
}
const useStyles = makeStyles<Theme, StyleProps>((theme: Theme, props: StyleProps) => ({
root: {
maxWidth: '100%',
backgroundImage: ({ post }) => post.mainImage
},
date: {
margin: theme.spacing(1),
marginLeft: theme.spacing(2)
},
heroimage: {
maxWidth: '100%',
height: 'auto',
objectFit: 'cover'
}
}))
TS 错误:
Type '(theme: Theme, props: any) => { root: (props: any) => CSSProperties; expandable: (props: any) => CSSProperties; iconContainer: { position: string; top: number; right: number; display: string; }; expandMoreIcon: (props: any) => CSSProperties; bannerContent: (props: any) => CSSProperties; }' is not assignable to type 'StyleRulesCallback<Theme, StyleProps, string>'.
我可以像您在其中看到的那样从样式块中访问内联道具,root
但这不是我想要的。