Skip to content

New types for SSG break the GetServerSidePropsResult type #19271

@PepijnSenders

Description

@PepijnSenders

Bug report

Describe the bug

In this PR the type of GetServerSidePropsResult was updated which breaks it because the | chain is a collection of incompatible types.

This is the TS error:

Property 'props' does not exist on type 'GetServerSidePropsResult<ServerSidePropsResult>'.
  Property 'props' does not exist on type '{ redirect: Redirect; }'.

When you do something like this:

const { ssrPayload } = (serverSidePropsResult).props;

Even typecasting doesn't work:

const { ssrPayload } = (serverSidePropsResult as GetServerSidePropsResult<
  ServerSidePropsResult
>).props;

I'm not sure how this should be fixed, maybe we should add this GetServerSidePropsResult as generic, like so:

export type GetServerSideProps<
  P extends { [key: string]: any } = { [key: string]: any },
  ResultType = GetServerSidePropsResult<P>,
  Q extends ParsedUrlQuery = ParsedUrlQuery
> = (
  context: GetServerSidePropsContext<Q>
) => Promise<ResultType>

... and then have different types for notFound and redirect.

Expected behavior

The types not to trigger an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions