9f1b4f5694
This adds `InferredStaticProps` and `InferredServerSideProps` to the typings. - [x] add types for type inference - [x] add explanation to docs - [ ] tests - are there any? ![inferred-props](https://user-images.githubusercontent.com/56154253/79068041-24bcab00-7cc4-11ea-8397-ed1b95fbeca7.gif) ### What does it do: As an alternative to declaring your Types manually with: ```typescript type Props = { posts: Post[] } export const getStaticProps: GetStaticProps<Props> = () => ({ posts: await fetchMyPosts(), }) export const MyComponent(props: Props) =>( // ... ); ``` we can now also infer the prop types with ```typescript export const getStaticProps = () => ({ // given fetchMyPosts() returns type Post[] posts: await fetchMyPosts(), }) export const MyComponent(props: InferredStaticProps<typeof getStaticProps>) =>( // props.posts will be of type Post[] ); ``` ### help / review wanted - [ ] I am no typescript expert. Although the solution works as intended for me, someone with more knowledge could probably improve the types. Any edge cases I missed? - [ ] are there any tests I should modify/ add? |
||
---|---|---|
.. | ||
components | ||
extension-order | ||
pages | ||
test | ||
next.config.js | ||
tsconfig.json |