Next.js, strict Typescript and missing / hard to find RenderPageResult type

断了今生、忘了曾经 提交于 2020-06-15 10:27:46

问题


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:

  1. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!