-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
(Docs) getStaticProps & getServerSideProps TS section (#40607) #40639
Conversation
Hey @sicikh thank you for working on improving the documentation 🙏. From my point of view I don't recommend mixing the type As you can see the last approach infers the correct types the first one uses a default type which is critical from my point of view. The same applies to |
Thanks for the reply! The problem given in your example is exactly what was missing in the existing documentation. The current behavior of types when we explicitly specify the type of functions is the standard behavior of TypeScript with type calculation. If we want to type the props in the page, while maintaining the explicit typing of That is why it is necessary to specify two examples in the documentation, with an explicit and implicit specification of the type of function of data fetching. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
} | ||
``` | ||
|
||
If you want to get inferred typings for your props, you can use `InferGetStaticPropsType<typeof getStaticProps>`: | ||
|
||
```tsx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will tsx work? I am unsure (worth checking)
…ercel#40639) Added examples to `getStaticProps` & `getServerSideProps` explicit and implicit typings for TypeScript. Related issues: fixes vercel#40607 Co-authored-by: Balázs Orbán <[email protected]>
…ercel#40639) Added examples to `getStaticProps` & `getServerSideProps` explicit and implicit typings for TypeScript. Related issues: fixes vercel#40607 Co-authored-by: Balázs Orbán <[email protected]>
Added examples to
getStaticProps
&getServerSideProps
explicit and implicit typings for TypeScript.Related issues: fixes #40607