Unverified Commit 3b9221ff authored by Gerrit Alex's avatar Gerrit Alex Committed by GitHub

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

## Bug

- [x] fixes #24684
- [x] Integration tests added

Intentionally omitted changing the types for `GetServerSideProps` etc. as its imo less reasonable to leverage SSR with a sync `getServerSideProps`. Can of course change the type too if you consider that also a valid case.
parent f29dfe24
......@@ -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
......@@ -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
......
......@@ -111,5 +111,16 @@ export default function EvilPage(): JSX.Element {
errorPage.restore()
}
})
it('should compile sync getStaticPaths & getStaticProps', async () => {
const page = new File(join(appDir, 'pages/ssg/[slug].tsx'))
try {
page.replace(/async \(/g, '(')
const output = await nextBuild(appDir, [], { stdout: true })
expect(output.stdout).toMatch(/Compiled successfully/)
} finally {
page.restore()
}
})
})
})
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