Closed andrrms closed 2 years ago
This does not fix #8. This PR would need to extract the return type of ctx.reply
and use it in ctx.replyWithEmoji
.
Major version change will not be required anymore.
Note that you're admin in the repo, there's no need to open pull requests from the fork. You can just open them from other branches in the same repo :)
This still does not solve the issue.
The aim is to make the following code compile:
import { Bot } from "https://deno.land/x/grammy/mod.ts"; import { hydrate, HydrateFlavor, } from "https://deno.land/x/grammy_hydrate/mod.ts"; type MyContext = EmojiFlavor<HydrateFlavor<Context>>; const bot = new Bot<MyContext>(""); bot.use(hydrate(), emojiParser(), async (ctx) => { const first = await ctx.reply("Ehh"); await first.delete(); const second = await ctx.replyWithEmoji`Hi! ${"robot"}`; await second.delete(); });
However, I cannot get it to work myself. It seems like
ReturnType
somehow swallows the changes that the inner transformative context flavour is performing toctx.reply
. Hence, the emoji flavour does not pick this up so it cannot provide the same type signature asctx.reply
has.I do not see how this can be fixed. Feel free to investigate. Perhaps the hydrate plugin needs to be adjusted, too, who knows.
It doesn't appear to be just ReturnType
, but rather a behavior of Typescript, itself. It seems like function type intersections are essentially treated as overloads, and Typescript will simply pick one of them for the return value type (without much consistency).
It seems like function type intersections are essentially treated as overloads
This is correct, it makes a lot of sense that this is the root cause of the issue.
I'm still unsure how to proceed from here.
@andrrms @KnorpelSenf Please take a look at https://github.com/grammyjs/hydrate/pull/1/files if it may be a potential workaround.
@andrrms can you please check out https://github.com/grammyjs/hydrate/pull/1 and confirm that everything works for you?
Changes made, needs review. If merged, plugin version will go to 2.0.0, as it also changes the name of the flavoring interface. Fix #8