GramIO API Reference / @gramio/composer/dist / EventContextOf
Type Alias: EventContextOf<T, E>
EventContextOf<
T,E> =Textendsobject?O&Eextends keyofD?D[E] :object:never
Defined in: composer/index.d.ts:410
Extracts the context type for a specific event from an EventComposer instance, combining global TOut (like ContextOf) and per-event TDerives[E].
Use this in custom event-specific methods (e.g. command, hears) instead of ContextOf<T> so that handlers registered via derive(event, handler) are visible in the handler's type:
Type Parameters
| Type Parameter |
|---|
T |
E extends string |
Example
ts
const methods = defineComposerMethods({
command<TThis extends ComposerLike<TThis>>(
this: TThis,
name: string,
handler: Middleware<MsgCtx & EventContextOf<TThis, "message">>,
): TThis {
return this.on("message", (ctx, next) => {
if (ctx.text === `/${name}`) return handler(ctx, next);
return next();
});
},
});
new Composer()
.derive("message", () => ({ t: (s: string) => s }))
.command("start", (ctx) => ctx.t("Hi!")); // ✅ t is visible