我正在ReactRouter 页面上查看此代码示例,这一段很有趣:
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 也不会从我学到的内容中自动提供类型注释......