发现了很多类似的问题,但没有一个能完全回答这个问题。您如何将 theme
和 props
传递给 Material UI makeStyles
钩子,但从最外层的闭包访问它们而不会发生 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
中看到的那样从样式块内联访问 props,但这不是我要找的。p>