diff --git a/src/server/types.ts b/src/server/types.ts index 1d4b7c8b..4cfe5f15 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -195,7 +195,7 @@ export interface LayoutRoute { // --- UNKNOWN PAGE --- // deno-lint-ignore no-explicit-any -export interface UnknownPageProps { +export interface UnknownPageProps> { /** The URL of the request that resulted in this page being rendered. */ url: URL; @@ -208,6 +208,7 @@ export interface UnknownPageProps { * `undefined`. */ data: T; + state: S; } export interface UnknownHandlerContext> diff --git a/tests/fixture/routes/_404.tsx b/tests/fixture/routes/_404.tsx index 48279ee2..ded12668 100644 --- a/tests/fixture/routes/_404.tsx +++ b/tests/fixture/routes/_404.tsx @@ -1,10 +1,19 @@ import { UnknownPageProps } from "$fresh/server.ts"; -export default function NotFoundPage({ data, url }: UnknownPageProps) { +type Data = { hello: string }; +type State = { root: string }; + +export default function NotFoundPage( + { data, state, url }: UnknownPageProps, +) { + // Checks that we have the correct type for state + state.root satisfies string; + return ( <>

404 not found: {url.pathname}

{data?.hello &&

Hello {data.hello}

} +

State root: {state.root}

); } diff --git a/tests/main_test.ts b/tests/main_test.ts index 8804a7d6..dc627aea 100644 --- a/tests/main_test.ts +++ b/tests/main_test.ts @@ -637,6 +637,7 @@ Deno.test({ const body = await resp.text(); assertStringIncludes(body, "404 not found: /not_found"); assertStringIncludes(body, "Hello Dino"); + assertStringIncludes(body, "State root: root_mw"); }, });