neet / next-composition

Next.js utility for reusing getServerSideProps and getStaticProps logics

Home Page:https://npm.im/next-composition

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Types: have Gssp<T> accept query generic param

mdaverde opened this issue ยท comments

commented

Some of the getServerSideProps functions I want to use have overridden the 2nd generic param after Props:

interface Query extends ParsedUrlQuery {
  slug: string;
}

export const getServerSideProps: GetServerSideProps<Props, Query> = async function (ctx) { ...};

But it doesn't seem like TS is happy when I use those generic overrides with this package:

export const getServerSideProps: GetServerSideProps<Props, Query> = composeServerSideProps({
  use: [withServerAuth, withBlogPost],
});

// TS error:
Type error: No overload matches this call.
  The last overload gave the following error.
    Type 'GetServerSideProps<Props, Query, PreviewData>' is not assignable to type 'Gssp<unknown>'.
      Types of parameters 'context' and 'context' are incompatible.
        Type 'GetServerSidePropsContext<ParsedUrlQuery, PreviewData>' is not assignable to type 'GetServerSidePropsContext<Query, PreviewData>'.
          Property 'slug' is missing in type 'Dict<string | string[]>' but required in type 'Query'.

Can we allow the second generic param through Gssp? Other users might actually need this in Gip<T> and Gsp<T> as well?

@mdaverde Thank you for reporting the issue.

I'm working on your proposal on #28 and I've just published the draft with next tag. Could you try it on your environment and let me know if it works in your case? You can install it with:

yarn add next-composition@next
commented

This works for me! Just tried it locally. Thank you ๐Ÿ‘

๐ŸŽ‰ This issue has been resolved in version 1.1.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€