rsnext/test/integration/typescript
Manu Schiller 9f1b4f5694
Add type inference for getStaticProps and getServerSideProps (#11842)
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?
2020-05-27 19:02:22 +00:00
..
components Add TypeScript Definitions for Sass (#10363) 2020-02-03 00:03:42 -05:00
extension-order Resolve TypeScript Extension in Correct Order (#12014) 2020-04-19 01:12:36 -04:00
pages Add type inference for getStaticProps and getServerSideProps (#11842) 2020-05-27 19:02:22 +00:00
test Add type inference for getStaticProps and getServerSideProps (#11842) 2020-05-27 19:02:22 +00:00
next.config.js Enable scss/sass support (#10571) 2020-02-18 08:35:12 -05:00
tsconfig.json Improve exported router types (#7853) 2019-07-11 13:35:39 -04:00