Skip to content

Commit

Permalink
Generic form of GetStaticProps and GetServerSideProps (vercel#10856)
Browse files Browse the repository at this point in the history
* Generic form of GetStaticProps and GetServerSideProps

* Oops, fix type!

* Add constraint for P

* Update packages/next/types/index.d.ts

Co-authored-by: Joe Haddad <timer150@gmail.com>
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
  • Loading branch information
3 people authored and ScriptedAlchemy committed Mar 17, 2020
1 parent 079a74e commit 6943521
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/next/types/index.d.ts
Expand Up @@ -64,12 +64,14 @@ export {
NextApiHandler,
}

export type GetStaticProps = (ctx: {
export type GetStaticProps<
P extends { [key: string]: any } = { [key: string]: any }
> = (ctx: {
params?: ParsedUrlQuery
preview?: boolean
previewData?: any
}) => Promise<{
props: { [key: string]: any }
props: P
revalidate?: number | boolean
}>

Expand All @@ -78,13 +80,15 @@ export type GetStaticPaths = () => Promise<{
fallback: boolean
}>

export type GetServerSideProps = (context: {
export type GetServerSideProps<
P extends { [key: string]: any } = { [key: string]: any }
> = (context: {
req: IncomingMessage
res: ServerResponse
params?: ParsedUrlQuery
query: ParsedUrlQuery
preview?: boolean
previewData?: any
}) => Promise<{ [key: string]: any }>
}) => Promise<{ props: P }>

export default next

0 comments on commit 6943521

Please sign in to comment.