Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InferGetStaticPropsType not working as expected #28638

Closed
livelo-app opened this issue Aug 31, 2021 · 3 comments
Closed

InferGetStaticPropsType not working as expected #28638

livelo-app opened this issue Aug 31, 2021 · 3 comments
Labels
bug Issue was opened via the bug report template.

Comments

@livelo-app
Copy link

livelo-app commented Aug 31, 2021

What version of Next.js are you using?

11.1.0

What version of Node.js are you using?

14.17.3

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

When attempting to use InferGetStaticPropsType I am getting my parameters' type as never.

The following link describes my issue.

#11842 (comment)

To better explain the bug - the bug only occurs if I include the following in getStaticProps:

  if (!res) {
    return {
      notFound: true
    }
  }

  if (res.length === 1) {
    return {
      redirect : {
        destination: `/city/sydney`,
        permanent: false
      }
    }
  }

It seems that including:

    return {
      notFound: true
    }

and:

    return {
      redirect : {
        destination: `/city/sydney`,
        permanent: false
      }
    }

will not allow for InferGetStaticPropsType to infer the correct type.

It also seems that including the type GetStaticPaths and GetStaticProps will force the InferGetStaticPropsType to return any as the type as seen in the thread below.
#11842 (comment)

I believe the most important bug to fix in this case is that the infer for getStaticProps only works in the case where we only return props. Not in the face where we may return redirect or notFound.

Expected Behavior

My static props type should be inferred however they currently are not.

To Reproduce

Set strict mode enabled and attempt to use InferGetStaticPropsType.

@livelo-app livelo-app added the bug Issue was opened via the bug report template. label Aug 31, 2021
@juanzgc
Copy link

juanzgc commented Aug 31, 2021

I'm facing the same issue - Currently I am getting any as the Inferred type

@ijjk
Copy link
Member

ijjk commented Sep 18, 2021

Hi, this is a duplicate of #15913 so closing this in favor of that one.

@ijjk ijjk closed this as completed Sep 18, 2021
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

4 participants