Adding TypeScript type checking to getInitialProps #11729
Unanswered
tomevans18
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
Within our codebase I am facing an issue with type checking for
getInitialProps
.When a page requires initial props and no
getInitialProps
is added for that page then no type checking is completed.This leads to undefined content being rendered to the page.
On looking through the source code,
NextComponentType
seems to allow forgetInitialProps
to be optional.With this optional value being in place the following code will not throw an error despite initial props being needed to render the page correctly.
But the following will error as
getInitialProps
is present but returning an incorrect object:My thinking is that
getInitialProps
should only be optional when there are no initial props provided to theNextComponentType
type but tbh this is beyond my knowledge of TS as you would need the key to be optional base on the present of a generic having a key which is also required.Has anyone found a solution to this issue?
Beta Was this translation helpful? Give feedback.
All reactions