reactjs - React TypeScript: (props: OwnProps) => Element' nu poate fi atribuit tipului 'FunctionComponent<{}>
Ca element JSX, totul este bine...
interface OwnProps {
children: JSX.Element;
location: Location;
}
export function Layout(props: OwnProps): JSX.Element {
Când îl schimb într-un component funcțional, primesc o eroare la Layout
interface OwnProps {
children: JSX.Element;
location: Location;
}
const Layout: React.FC = (props: OwnProps) => {
Eroarea este
Type '(props: OwnProps) => Element' is not assignable to type 'FunctionComponent<{}>'.
Types of parameters 'props' and 'props' are incompatible.
Property 'location' is missing in type '{ children?: ReactNode; }' but required in type 'OwnProps'.ts(2322)
layout.tsx(18, 3): 'location' is declared here.
Răspuns #1
React.FC este, de fapt, un tip generic. Trebuie să specifici tipul proprietății tale.
const Layout: React.FC<OwnProps> = (props: OwnProps) => {}
