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

GetStaticProps type error using latest TypeScript version with strict option set to true #32015

Closed
alexmkio opened this issue Dec 1, 2021 · 3 comments · Fixed by #33042
Closed
Labels
examples Issue/PR related to examples good first issue Easy to fix issues, good for newcomers

Comments

@alexmkio
Copy link

alexmkio commented Dec 1, 2021

What version of Next.js are you using?

12.0.5-canary.12

What version of Node.js are you using?

12.20.37

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

npm run build

Describe the Bug

After bumping TypeScript version to latest and enforcing strict mode I am presented with a type error for getStaticProps: GetStaticProps when implementing error catching and validation.

Expected Behavior

I would love for Next.js to have a built in type that accounts for TypeScript latest when run strict (as this is the same configuration found when running npx create-next-app@latest --typescript).

In the interim, I'd love any guidance to solve the issue as it stands. I am very new to Next.js and TypeScript and just can't figure out exactly what the type error wants me to do. I'd love to be able to build this application without changing strict to false or decrementing the TypeScript version used.

To Reproduce

If you install the Next.js with TypeScript example found here using npx create-next-app --example with-typescript with-typescript-app but bump the TypeScript version to the latest stable (4.5.2) and update the strict option to true in the tsconfig file you'll get the following error in ./pages/users/[id].tsx:

Screen Shot 2021-12-01 at 11 47 17 AM

Which is caused by this TypeScript rule released in v4.4 and true if strict===true. Solving for this issue triggers a type issue for GetStaticProps:

Screen Shot 2021-12-01 at 11 48 19 AM

I have a repo here with a handful of commits that demonstrate this process.

@alexmkio alexmkio added the bug Issue was opened via the bug report template. label Dec 1, 2021
@balazsorban44 balazsorban44 added examples Issue/PR related to examples good first issue Easy to fix issues, good for newcomers and removed bug Issue was opened via the bug report template. labels Dec 1, 2021
@timneutkens timneutkens changed the title getStaticProps: GetStaticProps type error using latest TypeScript version with strict option set to true GetStaticProps type error using latest TypeScript version with strict option set to true Dec 2, 2021
@vicente-s
Copy link
Contributor

I'm a first time contributor and I'd like to work on this issue. Should I just go for it or wait to be assigned?

@balazsorban44
Copy link
Member

balazsorban44 commented Jan 5, 2022

@vicente-s There is already an open PR, but the author seems to be unresponsive #32023

You could open a new PR and also add closes #32023 also, addressing all the requested changes from #32023

vicente-s added a commit to vicente-s/next.js that referenced this issue Jan 5, 2022
@kodiakhq kodiakhq bot closed this as completed in #33042 Jan 5, 2022
kodiakhq bot pushed a commit that referenced this issue Jan 5, 2022
## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`

Closes: #32023
Fixes: #32015
@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 Feb 4, 2022
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
…3042)

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`

Closes: vercel#32023
Fixes: vercel#32015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples good first issue Easy to fix issues, good for newcomers
Projects
None yet
3 participants