Skip to content

Commit

Permalink
fix(types): properly infer context type in ctx.pseudo handler
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaSemenov committed Jan 13, 2022
1 parent a65c115 commit 6ad9c21
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ declare module "grammy" {
handlePseudoUpdate(args: PseudoUpdateArg): Promise<void>
}
interface Composer<C extends Context> {
pseudo<C extends PseudoUpdateFlavoredContext>(
handler: MiddlewareFn<C>
): Composer<C>
pseudo<C2 extends PseudoUpdateFlavoredContext<C>>(
handler: MiddlewareFn<C2>
): Composer<C2>
}
interface Context extends PseudoUpdateFlavor {}
}
Expand Down Expand Up @@ -66,9 +66,10 @@ Bot.prototype.handlePseudoUpdate = async function (
})
}

Composer.prototype.pseudo = function <C extends PseudoUpdateFlavoredContext>(
this: Composer<C>,
handler: MiddlewareFn<C>
// FIXME: replace `any` with C/C2 from the interface declaration
Composer.prototype.pseudo = function (
this: Composer<any>,
handler: MiddlewareFn<any>
) {
return this.use((ctx, next) =>
ctx.update.pseudo ? handler(ctx, next) : next()
Expand Down

0 comments on commit 6ad9c21

Please sign in to comment.