所以下面的代码有效:
const HomePage: NextPage = () => (
<div>
<div>HomePage</div>
</div>
);
Run Code Online (Sandbox Code Playgroud)
不过,我想遵守 Airbnb 的风格指南,在本例中,它要求您使用命名函数,得出以下代码:
function HomePage(): NextPage {
return (
<div>
<div>HomePage</div>
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
然而,编译器对上面的代码给出了以下错误:
Type 'Element' is not assignable to type 'NextPage<{}, {}>'.
Type 'ReactElement<any, any>' is not assignable to type 'FunctionComponent<{}> & { getInitialProps?(context: NextPageContext): {} | Promise<{}>; }'.
Type 'ReactElement<any, any>' is not assignable to type 'FunctionComponent<{}>'.
Type 'ReactElement<any, any>' provides no match for the signature '(props: { children?: ReactNode; }, context?: any): ReactElement<any, any> …Run Code Online (Sandbox Code Playgroud)