Skip to content

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

@alexmkio

Description

@alexmkio

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    examplesIssue was opened via the examples template.good first issueEasy to fix issues, good for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions