fix: add missing state property to interface (#1579)
This commit is contained in:
+2
-1
@@ -195,7 +195,7 @@ export interface LayoutRoute {
|
|||||||
// --- UNKNOWN PAGE ---
|
// --- UNKNOWN PAGE ---
|
||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
export interface UnknownPageProps<T = any> {
|
export interface UnknownPageProps<T = any, S = Record<string, unknown>> {
|
||||||
/** The URL of the request that resulted in this page being rendered. */
|
/** The URL of the request that resulted in this page being rendered. */
|
||||||
url: URL;
|
url: URL;
|
||||||
|
|
||||||
@@ -208,6 +208,7 @@ export interface UnknownPageProps<T = any> {
|
|||||||
* `undefined`.
|
* `undefined`.
|
||||||
*/
|
*/
|
||||||
data: T;
|
data: T;
|
||||||
|
state: S;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UnknownHandlerContext<State = Record<string, unknown>>
|
export interface UnknownHandlerContext<State = Record<string, unknown>>
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
import { UnknownPageProps } from "$fresh/server.ts";
|
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<Data | undefined, State>,
|
||||||
|
) {
|
||||||
|
// Checks that we have the correct type for state
|
||||||
|
state.root satisfies string;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>404 not found: {url.pathname}</p>
|
<p>404 not found: {url.pathname}</p>
|
||||||
{data?.hello && <p>Hello {data.hello}</p>}
|
{data?.hello && <p>Hello {data.hello}</p>}
|
||||||
|
<p>State root: {state.root}</p>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -637,6 +637,7 @@ Deno.test({
|
|||||||
const body = await resp.text();
|
const body = await resp.text();
|
||||||
assertStringIncludes(body, "404 not found: /not_found");
|
assertStringIncludes(body, "404 not found: /not_found");
|
||||||
assertStringIncludes(body, "Hello Dino");
|
assertStringIncludes(body, "Hello Dino");
|
||||||
|
assertStringIncludes(body, "State root: root_mw");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user