【发布时间】:2020-07-28 15:37:12
【问题描述】:
假设我有一个名为 Link 的 React 组件:
function Link(props) {
return <a href={props.url}>{props.children}</a>
}
如何键入这个函数而不把它变成箭头函数?
这似乎不起作用:
interface ILink {
url: string
}
function Link(props: React.FC<ILink>) { }
// Property 'url' does not exist on type 'FC<ILink>'.
// Property 'children' does not exist on type 'FC<ILink>'.
但作为箭头功能,它会立即起作用吗?
interface ILink {
url: string
}
const Link: React.FC<ILink> = (props) => { }
// Compiles
【问题讨论】:
标签: reactjs typescript typescript-generics react-typescript