You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using both the GetServerSideProps type and InferGetServerSidePropsType, the type of the passed down props is any.
For example:
// We need this GetServerSideProps type when we want to have complete typing on the contextexportconstgetServerSideProps: GetServerSideProps=asynccontext=>{consttest={value: 'test'}// The type of test here is {value: string}return{props: {
test,},};};exportdefaultfunctionIndex({test}: InferGetServerSidePropsType<typeofgetServerSideProps>){// When trying to access our passed down prop here, the type is now any.return(<p>{test.value}</p> //);}
(Do not mind the parts underlined in red, that is just ESLint complaining :))
Expected Behavior
You should be able to combine both GetServerSideProps type and InferGetServerSidePropsType without losing the typing.
The GetServerSideProps type, as far as I know, is essential for the typing of the context and TS will complain in strict setups if you remove it since it turns the context into an implicit any.
Removing the context enables you to also remove the GetServerSideProps type but if you need both the context-typing and the infered typing, I'm pretty sure there is no solution.
To Reproduce
exportconstgetServerSideProps: GetServerSideProps=asynccontext=>{consttest={value: 'test'}// The type of test here is {value: string}return{props: {
test,},};};exportdefaultfunctionIndex({test}: InferGetServerSidePropsType<typeofgetServerSideProps>){// When trying to access our passed down prop here, the type is now any.return(<p>{test.value}</p> //);}
This happens both in the latest version of VS Code and Jetbrains Webstorm (the hinting and code-completion being any that is)
The text was updated successfully, but these errors were encountered:
driaug
added
bug
Issue was opened via the bug report template.
examples
Issue was opened via the examples template.
labels
Aug 26, 2021
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
locked as resolved and limited conversation to collaborators
Jan 27, 2022
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
bugIssue was opened via the bug report template.examplesIssue was opened via the examples template.
What example does this report relate to?
data-fetching (getServerSideProps with TS)
What version of Next.js are you using?
10.0.9
What version of Node.js are you using?
14.17.1
What browser are you using?
Chrome
What operating system are you using?
Windows (also happens on my mac)
How are you deploying your application?
next dev
Describe the Bug
When using both the
GetServerSideProps
type andInferGetServerSidePropsType
, the type of the passed down props isany
.For example:
(Do not mind the parts underlined in red, that is just ESLint complaining :))
Expected Behavior
You should be able to combine both
GetServerSideProps
type andInferGetServerSidePropsType
without losing the typing.The
GetServerSideProps
type, as far as I know, is essential for the typing of the context and TS will complain in strict setups if you remove it since it turns the context into an implicit any.Removing the context enables you to also remove the
GetServerSideProps
type but if you need both the context-typing and the infered typing, I'm pretty sure there is no solution.To Reproduce
This happens both in the latest version of VS Code and Jetbrains Webstorm (the hinting and code-completion being
any
that is)The text was updated successfully, but these errors were encountered: