Skip to content

GramIO API Reference / @gramio/composer/dist / ComposerLike

Type Alias: ComposerLike<T>

ComposerLike<T> = object

Defined in: composer/index.d.ts:257

Minimal structural type for constraining this in custom composer methods.

Use as an F-bounded constraint on TThis so that this.on(...) is typed and returns TThis without requiring as any:

Example

ts
command<TThis extends ComposerLike<TThis>>(
  this: TThis,
  name: string,
  handler: Middleware<MsgCtx & ContextOf<TThis>>,
): TThis {
  const inner: Middleware<MsgCtx & ContextOf<TThis>> = (ctx, next) => {
    if (ctx.text === `/${name}`) return handler(ctx, next);
    return next();
  };
  return this.on("message", inner); // typed — no cast needed
}

Type Parameters

Type ParameterDefault type
Tunknown

Methods

on()

on(event, handler): T

Defined in: composer/index.d.ts:258

Parameters

ParameterType
eventany
handlerany

Returns

T