Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit bd32a27

Browse files
authored
Add Props generic to SSROptions (#402)
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.
1 parent d4efff8 commit bd32a27

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

examples/hello-world-ssr/pages/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import React from 'https://esm.sh/react'
1+
import React, { FC } from 'https://esm.sh/react'
22
import type { SSROptions } from 'https://deno.land/x/aleph/types.d.ts'
33

4-
export const ssr: SSROptions = {
4+
type Props = {
5+
serverTime: number
6+
}
7+
8+
export const ssr: SSROptions<Props> = {
59
props: async router => {
610
return {
711
$revalidate: 1, // revalidate props after 1 second
@@ -13,8 +17,10 @@ export const ssr: SSROptions = {
1317
}
1418
}
1519

16-
export default function Page(props) {
20+
const Page: FC<Props> = (props) => {
1721
return (
1822
<p>Now: {props.serverTime}</p>
1923
)
2024
}
25+
26+
export default Page

types.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,15 @@ export type GlobalSSROptions = {
236236
/**
237237
* The **SSR** props.
238238
*/
239-
export type SSRProps = {
240-
[key: string]: any
239+
export type SSRProps<Props> = Props & {
241240
$revalidate?: number
242241
}
243242

244243
/**
245244
* The **SSR** options for pages.
246245
*/
247-
export type SSROptions = {
248-
props?(router: RouterURL): (SSRProps | Promise<SSRProps>)
246+
export type SSROptions<Props = {}> = {
247+
props?(router: RouterURL): (SSRProps<Props> | Promise<SSRProps<Props>>)
249248
paths?(): (string[] | Promise<string[]>)
250249
}
251250

0 commit comments

Comments
 (0)