definePluginFor
definePluginFor<
TEnv>(): <TName,TProvides,TRequires,TClient>(config) =>CfastPlugin<TName,Awaited<TProvides>,RequiresFromPlugins<TRequires>,TClient,TEnv>
Defined in: packages/core/src/define-plugin.ts:175
Returns an env-typed definePlugin factory.
The scaffolded Cloudflare.Env type from worker-configuration.d.ts is
not known to @cfast/core at build time, so the generic definePlugin
exposes ctx.env as the loose Record<string, unknown> shape and
consumers have to cast bindings (e.g. ctx.env.DB as D1Database). Apps
that want precise bindings call this factory once with their env type
and re-export the typed definePlugin from a local module:
import { definePluginFor } from "@cfast/core";
export const definePlugin = definePluginFor<Cloudflare.Env>();Plugin authors then import from their local module and get ctx.env.DB
typed as D1Database without any casting:
import { definePlugin } from "~/plugins/define-plugin";
export const dbPlugin = definePlugin({ name: "db", setup(ctx) { const db = ctx.env.DB; // D1Database, no cast return { client: createDb({ d1: db }) }; },});The returned factory has the same shape as definePlugin (with the curried legacy overload preserved) so existing code that switches from the generic form to the env-typed form only needs an import swap.
Type Parameters
Section titled “Type Parameters”TEnv
Returns
Section titled “Returns”<
TName,TProvides,TRequires,TClient>(config):CfastPlugin<TName,Awaited<TProvides>,RequiresFromPlugins<TRequires>,TClient,TEnv>
Type Parameters
Section titled “Type Parameters”TName extends string
TProvides
Section titled “TProvides”TProvides
TRequires
Section titled “TRequires”TRequires extends readonly CfastPlugin<string, unknown, any, unknown, any>[] = []
TClient
Section titled “TClient”TClient = unknown
Parameters
Section titled “Parameters”config
Section titled “config”client?
Section titled “client?”TClient
TName
Provider?
Section titled “Provider?”ComponentType<{ children: ReactNode; }>
requires?
Section titled “requires?”TRequires
(ctx) => TProvides | Promise<TProvides>
Returns
Section titled “Returns”CfastPlugin<TName, Awaited<TProvides>, RequiresFromPlugins<TRequires>, TClient, TEnv>