我一直在努力解决以下打字稿错误。我们逐渐将文件更改为打字稿。作为打字稿的初学者,我很难用谷歌出错。我只想先了解错误,然后再搜索解决方案。
TS2339: Property 'classes' does not exist on type 'PropsWithChildren<ConsistentWith<ConsistentWith<{},{ classes: Record<"root" | "switchBase" | "thumb" | "track" | "checked" | "focusVisible",string>; }>,string>; }> | ConsistentWith<...>>'.
我尝试在道具中添加{classname: string}
,但随后出现新错误。
const IOSSwitch = withStyles(theme => ({
root: {
width: 42,height: 26,padding: 0,margin: theme.spacing(1),},switchBase: {
padding: 1,'&$checked': {
transform: 'translateX(16px)',color: theme.palette.common.white,'& + $track': {
backgroundColor: '#52d869',opacity: 1,border: 'none','&$focusVisible $thumb': {
color: '#52d869',border: '6px solid #fff',thumb: {
width: 24,height: 24,track: {
borderRadius: 26 / 2,border: `1px solid ${theme.palette.grey[400]}`,backgroundColor: theme.palette.grey[50],transition: theme.transitions.create(['background-color','border']),checked: {},focusVisible: {},}))(({ classes,...props }) => {
return (
<Switch
focusVisibleclassname={classes.focusVisible}
disableRipple
classes={{
root: classes.root,switchBase: classes.switchBase,thumb: classes.thumb,track: classes.track,checked: classes.checked,}}
{...props}
/>
);
});
正在使用的开关组件
<IOSSwitch
checked={state.checkedB}
onChange={handleChange('checkedB')}
value="checkedB"
/>