shadcn/next-mdx

getMdxNode's context type is incompatible with nextjs's

tyteen4a03 opened this issue · 2 comments

For this code:

import { GetStaticProps } from 'next';
export const getStaticProps: GetStaticProps = async (context) => {
    const post = await getMdxNode('post', context);

    if (!post) {
        return {
            notFound: true,
        };
    }

    return {
        props: {
            post,
        },
    };
};

TypeScript is emitting this warning for L3:

TS2345: Argument of type 'GetStaticPropsContext<ParsedUrlQuery>' is not assignable to parameter of type 'string | GetStaticPropsContext<Dict<string[]>>'.  
Type 'GetStaticPropsContext<ParsedUrlQuery>' is not assignable to type 'GetStaticPropsContext<Dict<string[]>>'.
Type 'ParsedUrlQuery' is not assignable to type 'Dict<string[]>'. 
Index signatures are incompatible.
Type 'string | string[] | undefined' is not assignable to type 'string[] | undefined'.
Type 'string' is not assignable to type 'string[] | undefined'.

Can you try the following:

type Props = {
  post: Post
  snippets: Snippet[]
}

// We can narrow down context to an array of string because this is what getStaticPaths will set it to.
type Params = NodeJS.Dict<string[]>

export const getStaticProps: GetStaticProps<Props, Params> = async (
  context
) => {
  const post = await getMdxNode<Post>("post", context)

  if (!post) {
    return {
      notFound: true,
    }
  }

  return {
    props: {
      post,
    },
  }
}

Closing this as stale. Feel free to reopen if not. Thank you.