Skip to content
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

fix(types): allow nonpromise return types for static functions #24685

Merged
merged 6 commits into from
May 25, 2021
8 changes: 5 additions & 3 deletions packages/next/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ export type GetStaticPropsResult<P> =
export type GetStaticProps<
P extends { [key: string]: any } = { [key: string]: any },
Q extends ParsedUrlQuery = ParsedUrlQuery
> = (context: GetStaticPropsContext<Q>) => Promise<GetStaticPropsResult<P>>
> = (
context: GetStaticPropsContext<Q>
) => Promise<GetStaticPropsResult<P>> | GetStaticPropsResult<P>

export type InferGetStaticPropsType<T> = T extends GetStaticProps<infer P, any>
? P
: T extends (
context?: GetStaticPropsContext<any>
) => Promise<GetStaticPropsResult<infer P>>
) => Promise<GetStaticPropsResult<infer P>> | GetStaticPropsResult<infer P>
? P
: never

Expand All @@ -131,7 +133,7 @@ export type GetStaticPathsResult<P extends ParsedUrlQuery = ParsedUrlQuery> = {

export type GetStaticPaths<P extends ParsedUrlQuery = ParsedUrlQuery> = (
context: GetStaticPathsContext
) => Promise<GetStaticPathsResult<P>>
) => Promise<GetStaticPathsResult<P>> | GetStaticPathsResult<P>

export type GetServerSidePropsContext<
Q extends ParsedUrlQuery = ParsedUrlQuery
Expand Down