Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need workaround for filter function overload's type inference #395

Open
KnightNiwrem opened this issue Mar 12, 2023 · 1 comment
Open

Need workaround for filter function overload's type inference #395

KnightNiwrem opened this issue Mar 12, 2023 · 1 comment

Comments

@KnightNiwrem
Copy link
Contributor

yarn add @grammyjs/ratelimiter
yarn add https://github.com/grammyjs/grammY.git
import { Bot, Context } from 'grammy';
import { limit } from '@grammyjs/ratelimiter';

type FromContext = Context & { from: NonNullable<Context['from']> };

const bot = new Bot('');
const MyC = bot.filter((ctx): ctx is FromContext=> !!ctx.from);
MyC.filter(
  ctx => true,
  limit({ onLimitExceeded: ctx => ctx.answerCallbackQuery() }),
);
MyC.filter(
  ctx => true,
  ctx => ctx.from.first_name,
);
// In node_modules > grammy > out > composer.d.ts
// swap the ordering of the following lines to toggle different errors
filter<D extends C>(predicate: (ctx: C) => ctx is D, ...middleware: Array<Middleware<D>>): Composer<D>;
filter(predicate: (ctx: C) => MaybePromise<boolean>, ...middleware: Array<Middleware<C>>): Composer<C>;
@KnorpelSenf
Copy link
Member

Context: this is caused by a bug in TypeScript. It would be nice if we found a workaround so we don't have to wait for Microsoft to fix it.

Also, we should probably open an issue about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants