简体   繁体   English

“ClassNameMap”类型上不存在属性“包装器”<never> ' Typescript</never>

[英]Property 'wrapper' does not exist on type 'ClassNameMap<never>' Typescript

Good Evening, In my .tsx file it says that wrapper does not exist.晚上好,在我的.tsx文件中,它说wrapper不存在。 I am using material UI and Typescript.我正在使用材质 UI 和 Typescript。 I am also new to Typescript and working on converting over.我也是 Typescript 的新手,正在努力转换。 I am not sure why it says that it does not exist when it worked before the conversion.我不确定为什么它说它在转换之前工作时不存在。 Any guidance is much appreciated.非常感谢任何指导。

Admin.tsx管理员.tsx

 import React, {useEffect, useState, createRef} from "react"; import {Switch, Route, Redirect } from "react-router-dom"; // @material-ui/core components import { makeStyles } from "@material-ui/core"; // core components import Navbar from "../components/Navbars/Navbar.js"; import Footer from "../components/Footer/Footer.js"; import Sidebar from "../components/Sidebar/Sidebar.js"; import routes from "../routes"; import appStyle from "../assets/jss/material-dashboard-react/layouts/adminStyle"; import lgImage from "../assets/img/site-logo.png"; import bgImage from '../assets/img/sidebar-2.jpg'; let ps; const switchRoutes = ( <Switch> {routes.map((prop, key) => { if (prop.layout === "/admin") { return ( <Route path={prop.layout + prop.path} component={prop.component} key={key} /> ); } return null; })} <Redirect from="/admin" to="/admin/login" /> </Switch> ); const useStyles = makeStyles(appStyle); export default function Admin({...rest }) { // styles const classes = useStyles(); return ( <div className={classes.wrapper}> {handleSideBarLogin()? null: <Sidebar routes={routes} logoText={"02DesignStudio"} logo={logo} image={image} handleDrawerToggle={handleDrawerToggle} open={mobileOpen} color={color} {...rest} /> } <div className={classes.mainPanel} ref={mainPanel}> <Navbar routes={routes} handleDrawerToggle={handleDrawerToggle} {...rest} /> {getRoute()? ( <div className={classes.content}> <div className={classes.container}>{switchRoutes}</div> </div> ): ( <div className={classes.map}>{switchRoutes}</div> )} {getRoute()? <Footer />: null} </div> </div> ); }

AdminStyl管理风格

 import { drawerWidth, transition, container } from "../../material-dashboard-react"; import { withStyles } from "@material-ui/core"; const appStyle = theme => (withStyles({ wrapper: { position: "relative", top: "0", height: "100vh" }, mainPanel: { [theme.breakpoints.up("md")]: { width: `calc(100% - ${drawerWidth}px)` }, overflow: "auto", position: "relative", float: "right", ...transition, maxHeight: "100%", width: "100%", overflowScrolling: "touch" }, content: { marginTop: "70px", padding: "30px 15px", minHeight: "calc(100vh - 123px)" }, container, map: { marginTop: "70px" } })); export default appStyle;

Error错误

 TypeScript error in /Users/augustshah/Documents/Coding-Tools-new/Projects/Payment-Dashboard/src/layouts/Admin.tsx(105,29): Property 'wrapper' does not exist on type 'ClassNameMap<never>'. TS2339 103 | 104 | return ( > 105 | <div className={classes.wrapper}> | ^ 106 | {handleSideBarLogin()? 107 | null: <Sidebar 108 | routes={routes}

withStyles is a Higher-order component that cannot be used as a hook like you are trying to do here. withStyles是一个高阶组件,不能像您在这里尝试做的那样用作钩子。 It is different to makeStyles that you tried to use in the other question.您尝试在另一个问题中使用的makeStyles是不同的。

The docs show you how to use it - for your Admin.tsx it would probably look something like this: 文档向您展示了如何使用它 - 对于您的 Admin.tsx,它可能看起来像这样:

function Admin({ classes, ...rest }) {
  return (
    <div className={classes.wrapper}>
      // <...>
    </div>
  );
}

export default appStyle(Admin);

Also you need to update appStyle :您还需要更新appStyle

const appStyle = withStyles(theme => ({
  // ...
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM