Unverified Commit ea0cdc5a authored by Denis Homolík's avatar Denis Homolík Committed by GitHub

Add revalidate to the GetStaticPropsResult (#29919)

Fixes #28687

According to the answer in #28687, `GetStaticPropsResult` should allow specifying `revalidate` next to the `notFound: true`. Right now it's missing in the types def and allows to return any type. Also this may lead to confusion, that `revalidate` can't be used with the `notFound: true`

Example:
```ts
export const getStaticProps: GetStaticProps = async ({ locale }) => {
  const data = await fetchData();

  if (!data) {
    return {
      notFound: true,
      revalidate: new Date() // ts doesn't know the revalidate field and allows this
    };
  }

  return {
    props: { data },
    revalidate: new Date() // ts know the revalidate field, so it doesn't allow this
  };
};
```

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes
parent fd5522d9
......@@ -109,7 +109,7 @@ export type GetStaticPropsContext<
export type GetStaticPropsResult<P> =
| { props: P; revalidate?: number | boolean }
| { redirect: Redirect; revalidate?: number | boolean }
| { notFound: true }
| { notFound: true; revalidate?: number | boolean }
export type GetStaticProps<
P extends { [key: string]: any } = { [key: string]: any },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment