【发布时间】:2019-02-20 10:35:14
【问题描述】:
我在 ReactRouter 页面上查看this code example,这篇文章很有趣:
const PrivateRoute = ({ component: Component, ...rest }) => (
<Route
{...rest}
render={props =>
fakeAuth.isAuthenticated ? (
<Component {...props} />
) : (
<Redirect
to={{
pathname: "/login",
state: { from: props.location }
}}
/>
)
}
/>
);
component: Component 部分看起来像一个类型注释。当我将此示例放入一个空文件时,Webstorm 没有抱怨,但我没有看到它们使用 Flow 或 TypeScript 或导入中的任何内容。
JavaScript 已经有类型注解了吗?当我搜索时,我在 MDN 上没有看到任何关于此的内容,而且 React 也不会自动提供我所学到的类型注释......
【问题讨论】:
-
这是 ES6 别名,所以它是一个有效的 Javascript
标签: javascript reactjs react-router