From 42f648bff4f2fe92198e945dd6358eaa367452c3 Mon Sep 17 00:00:00 2001 From: Tate Barber Date: Wed, 22 Sep 2021 00:30:36 -0500 Subject: [PATCH] Add Props generic to SSROptions This change adds a generic type parameter to the `SSROptions` type that, as a result, provides a type for the returned props object. This models after React's type generics for component types. --- examples/hello-world-ssr/pages/index.tsx | 12 +++++++++--- types.d.ts | 7 +++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/hello-world-ssr/pages/index.tsx b/examples/hello-world-ssr/pages/index.tsx index 0e6e73e0d..fa3cecb68 100644 --- a/examples/hello-world-ssr/pages/index.tsx +++ b/examples/hello-world-ssr/pages/index.tsx @@ -1,7 +1,11 @@ -import React from 'https://esm.sh/react' +import React, { FC } from 'https://esm.sh/react' import type { SSROptions } from 'https://deno.land/x/aleph/types.d.ts' -export const ssr: SSROptions = { +type Props = { + serverTime: number +} + +export const ssr: SSROptions = { props: async router => { return { $revalidate: 1, // revalidate props after 1 second @@ -13,8 +17,10 @@ export const ssr: SSROptions = { } } -export default function Page(props) { +const Page: FC = (props) => { return (

Now: {props.serverTime}

) } + +export default Page diff --git a/types.d.ts b/types.d.ts index c19bf0e6c..de2ab7e6f 100644 --- a/types.d.ts +++ b/types.d.ts @@ -236,16 +236,15 @@ export type GlobalSSROptions = { /** * The **SSR** props. */ -export type SSRProps = { - [key: string]: any +export type SSRProps = Props & { $revalidate?: number } /** * The **SSR** options for pages. */ -export type SSROptions = { - props?(router: RouterURL): (SSRProps | Promise) +export type SSROptions = { + props?(router: RouterURL): (SSRProps | Promise>) paths?(): (string[] | Promise) }