reactjs - React App.tsx 在使用 withStyles 时出现“不可分配”错误
我使用 React(TypeScript)和 Material-UI 启动了一个默认的 Web 应用程序。
我尝试将以下代码实现为类组件。如果我不更改代码并像例子中那样使用它,它是可以工作的,但我想创建一个类组件而不是函数组件:https://material-ui.com/components/drawers/#MiniDrawer.tsx
我的实现:App.tsx
const styles = (theme: Theme) => createStyles({
// ...
});
interface Props extends WithStyles<typeof styles> {
}
interface State {
open: boolean;
}
class App extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
open: false
};
}
...
public render(): JSX.Element {
const { classes } = this.props;
return (
...
);
}
}
export default withStyles(styles)(App);
使用我的代码后,我得到以下错误。
TypeScript error in D:/project/src/index.tsx(10,8):
Type '{}' is not assignable to type '(value: JSSFontface, index: number, array: JSSFontface[]) => unknown'.
Type '{}' provides no match for the signature '(value: JSSFontface, index: number, array: JSSFontface[]): unknown'. TS2322
8 | ReactDOM.render(
9 | <React.StrictMode>
> 10 | <App />
| ^
11 | </React.StrictMode>,
12 | document.getElementById('root')
13 | );
