diff --git a/src/server/types.ts b/src/server/types.ts index c9f32145..4e677fea 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -325,7 +325,7 @@ export interface Island { // --- PLUGINS --- -export interface Plugin { +export interface Plugin> { /** The name of the plugin. Must be snake-case. */ name: string; @@ -359,7 +359,7 @@ export interface Plugin { routes?: PluginRoute[]; - middlewares?: PluginMiddleware[]; + middlewares?: PluginMiddleware[]; } export interface PluginRenderContext { @@ -411,11 +411,11 @@ export interface PluginRenderFunctionResult { requiresHydration: boolean; } -export interface PluginMiddleware { +export interface PluginMiddleware> { /** A path in the format of a filename path without filetype */ path: string; - middleware: Middleware; + middleware: Middleware; } export interface PluginRoute { diff --git a/tests/fixture_plugin/routes/test.tsx b/tests/fixture_plugin/routes/test.tsx index ca9d1d46..c1c11ef7 100644 --- a/tests/fixture_plugin/routes/test.tsx +++ b/tests/fixture_plugin/routes/test.tsx @@ -1,14 +1,14 @@ -import { Handlers, PageProps } from "../../../server.ts"; +import { HandlerContext, Handlers, PageProps } from "../../../server.ts"; -export const handler: Handlers = { - async GET(_req, ctx) { +export const handler: Handlers = { + async GET(_req, ctx: HandlerContext) { const resp = await ctx.render(); return resp; }, }; -export default function Home(props: PageProps) { - const value = props.state.test as string; +export default function Home(props: PageProps) { + const value = props.state.test; return (

{value}

diff --git a/tests/fixture_plugin/utils/route-plugin.ts b/tests/fixture_plugin/utils/route-plugin.ts index a8c4de72..fcea4f7a 100644 --- a/tests/fixture_plugin/utils/route-plugin.ts +++ b/tests/fixture_plugin/utils/route-plugin.ts @@ -7,7 +7,9 @@ interface Options { title: string; } -export default function routePlugin(options: Options): Plugin { +export default function routePlugin( + options: Options, +): Plugin<{ test: string }> { return { name: "routePlugin", middlewares: [{ diff --git a/tests/fixture_plugin/utils/sample_routes/_middleware.ts b/tests/fixture_plugin/utils/sample_routes/_middleware.ts index cd7407fc..f702b7a8 100644 --- a/tests/fixture_plugin/utils/sample_routes/_middleware.ts +++ b/tests/fixture_plugin/utils/sample_routes/_middleware.ts @@ -1,6 +1,9 @@ import { MiddlewareHandlerContext } from "$fresh/server.ts"; -export async function handler(_req: Request, ctx: MiddlewareHandlerContext) { +export async function handler( + _req: Request, + ctx: MiddlewareHandlerContext<{ test: string }>, +) { ctx.state.test = "look, i'm set from a plugin!"; const resp = await ctx.next(); return resp;