Typescript error when using MenuTemplate with Markdown parse mode
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
telegrafwithtelegraf-inline-menu, I don't have another option, because I usenesjswithnestjs-telegraf. Grammy (currently) doesn't provide any working lib fornestjs telegrafversion:^4.8.6telegraf-inline-menuversion: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:
- Create a function that returns object with
textandparse_modeprops:
const getMenuMessage = (context: Context) => {
const menuMessage = { text: 'Hello, world!', parse_mode: 'Markdown' };
return menuMessage;
}
- Create a menu template using that function:
const template = new MenuTemplate(getMenuMessage);
- 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

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
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?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Not sure what the problem might be and there is no activity here. If its still relevant feel free to comment and reopen.