grammy-inline-menu icon indicating copy to clipboard operation
grammy-inline-menu copied to clipboard

Typescript error when using MenuTemplate with Markdown parse mode

Open ismoiliy98 opened this issue 3 years ago • 2 comments

Describe the bug Typescript type check error while using MenuTemplate with Markdown parse mode.

Versions Did you updated grammY and grammy-inline-menu to the latest version?

  • Nope. I use telegraf with telegraf-inline-menu, I don't have another option, because I use nesjs with nestjs-telegraf. Grammy (currently) doesn't provide any working lib for nestjs
  • telegraf version: ^4.8.6
  • telegraf-inline-menu version: 6.3.0

What version of NodeJS (and TypeScript) do you use?

  • Version of NodeJS: 16.13.0
  • Version of TypeScript: ^4.7.4

To Reproduce Steps to reproduce the behavior:

  1. Create a function that returns object with text and parse_mode props:
const getMenuMessage = (context: Context) => {
  const menuMessage = { text: 'Hello, world!', parse_mode: 'Markdown' };

  return menuMessage;
}
  1. Create a menu template using that function:
const template = new MenuTemplate(getMenuMessage);
  1. You should the typescript error:
error TS2345: Argument of type '(context: Context) => { text: string; parse_mode: string; }' is not assignable to parameter of type 'ConstOrContextPathFunc<Context, Body>'.
  Type '(context: Context) => { text: string; parse_mode: string; }' is not assignable to type 'ContextPathFunc<Context, Body>'.
    Type '{ text: string; parse_mode: string; }' is not assignable to type 'ConstOrPromise<Body>'.
      Type '{ text: string; parse_mode: string; }' is missing the following properties from type 'MediaBody': type, media

Expected behavior There should not be a type error

Screenshots image image

P.S Any workarounds to fix this? A stupid hack is to convert the return type of the function which returns the menu message to a string using as unknown as string

ismoiliy98 avatar Aug 11 '22 15:08 ismoiliy98

Sorry for my late response. Im not sure why this fails, just from looking at it, it looks fine.

Personally I would try to specify the return type of the getMenuTitle function. That way your error should already be in the function as the return type is not matching with what is returned. Then error messages are more helpful usually.

I hope this helps?

EdJoPaTo avatar Aug 21 '22 06:08 EdJoPaTo

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Sep 20 '22 18:09 stale[bot]

Not sure what the problem might be and there is no activity here. If its still relevant feel free to comment and reopen.

EdJoPaTo avatar Jun 19 '23 14:06 EdJoPaTo