typescript - 关于使用 withRouter 破坏别名的打字稿警告
问题描述
我在反应中有一个用纯javascript编写的类组件:
class Auth extends Component {
render() {
const { component: Component, ...rest } = this.props //error: Property 'component' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'.ts(2339)
const isAuth = getUser() //some function
return (
<Route
{...rest}
render={props =>
isAuth ? (
<Component {...props} />
) : (
<Redirect
to={{
pathname: '/login'
}}
/>
)
}
/>
)
}
}
export default withRouter(Auth) //error: Argument of type 'typeof Auth' is not assignable to parameter of type 'ComponentClass<RouteComponentProps<any, StaticContext, any>, any> | FunctionComponent<RouteComponentProps<any, StaticContext, any>> | (FunctionComponent<...> & ComponentClass<...>) | (ComponentClass<...> & FunctionComponent<...>)'.
但是 Typescript 发出警告,我上面的代码有什么问题?
解决方案
推荐阅读
- python - Pandas 如何确定某事物是否为“标量”?
- atlassian-sourcetree - 数据库中是否需要 .git 文件夹?
- d3.js - 3 级嵌套数据的 D3v4 更新模式遇到问题
- python - 为给定的值范围生成给定大小的所有可能的元组组合
- vue.js - 量角器 - 使用 by.id 时“为定位器找到多个元素”
- java - Json 反序列化并在启动时保存到 JPA
- python - 如何根据 random.choice 的结果和输入做出 if 和 elif 语句
- angular - 如何对 ChildNode 进行类型保护?或者将 ChildNode 方法与 Typescript 一起使用?
- java - 使用一个属性在自定义列表中查找对象的 indexOf
- java - @RequestBody 没有将 JSON 映射到 Java 对象 - Spring Boot