问题
I have strict TypeScript setup. (Due to 'no implicit any return type' error/warning
) I needed return type of one function in a custom Document component to be like:
ctx.renderPage = (): RenderPageResult | Promise<RenderPageResult> =>
originalRenderPage({
enhanceApp: App => (props): ReactElement => sheets.collect(<App {...props} />),
});
but couldn't figure out how to get a hold of RenderPageResult
.
So I've added following to the next-env.d.ts
file:
/// <reference types="next/dist/next-server/lib/utils" />
And imported RenderPageResult
like this into the Document component:
import { RenderPageResult } from 'next/dist/next-server/lib/utils';
Is this correct way going about it?
Is there a better/correct way of doing it?
Thanks.
PS
Project uses "next": "^9.1.4",
which is pretty much the latest release at the time of writing.
PPS
Question originally posted here: https://spectrum.chat/next-js/general/next-js-strict-typescript-and-missing-hard-to-find-renderpageresult-type~6cf4b4a8-769f-4a99-a72e-8ee2f8ad17db
Updates:
- the
next-env.d.ts
file update mentioned above seems to add zero value (and based on TS docs probs is complete misunderstanding of the declaration files on my part).
来源:https://stackoverflow.com/questions/59245701/next-js-strict-typescript-and-missing-hard-to-find-renderpageresult-type