Reactjs 我如何申报两个“;res";在参数中使用getInitialProps和react typescript中的NextPageContext?

Reactjs 我如何申报两个“;res";在参数中使用getInitialProps和react typescript中的NextPageContext?,reactjs,typescript,next.js,Reactjs,Typescript,Next.js,下面是我使用getInitialProps在服务器中获取数据的代码。但是正如您所看到的,有两个res参数是以不同的目的声明的。如何申报或分开?我发现一个错误 ProductDetails.getInitialProps = ({res}, res: NextPageContext) => { const productModel = _.get(res, 'locals.productModel', {}); const isMobile = _.get(res, 'locals.

下面是我使用getInitialProps在服务器中获取数据的代码。但是正如您所看到的,有两个res参数是以不同的目的声明的。如何申报或分开?我发现一个错误

ProductDetails.getInitialProps = ({res}, res: NextPageContext) => {
  const productModel = _.get(res, 'locals.productModel', {});
  const isMobile = _.get(res, 'locals.isMobile', false);
  const { query: { data }, } = res;
  return {
    page: { ...(data as Model)?.page } || emptyModel,
    ...productModel,
    isMobile,
  };
};

getInitialProps
只接收一个上下文对象,该对象又包含一个
res
对象。第二个
res
始终未定义。我可以在父组件中声明两个getInitialProps吗?不能为同一页声明两个
getInitialProps
。你为什么要这么做?用例是什么?因为res和res:NextPageContext的值不同。第一个res用于productModel,第二个res:NextPageContext用于queryAre您是否从某处显式地将这两个
res
传递到页面
getInitialProps
?您总是可以像这样重命名其中一个:
({res:modelRes},res:NextPageContext)