From bc4710d00ea2a935b3b9baa680b09dc5e8d4b240 Mon Sep 17 00:00:00 2001 From: KnorpelSenf Date: Sat, 22 Jun 2024 00:06:59 +0200 Subject: [PATCH 1/2] fix: resolve type conflict of ctx.chatId for callback queries --- src/filter.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/filter.ts b/src/filter.ts index 371225fe..2ce60db4 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -638,7 +638,8 @@ interface Shortcuts { : [U["message_reaction"]] extends [object] ? number : [U["message_reaction_count"]] extends [object] ? number : undefined; - chatId: [Shortcuts["chat"]] extends [object] ? number + chatId: [U["callback_query"]] extends [object] ? number | undefined + : [Shortcuts["chat"]] extends [object] ? number : [U["business_connection"]] extends [object] ? number : undefined; // inlineMessageId: disregarded here because always optional on both types From 9a544e675461630f04faf4d9a4d9496ccf54e068 Mon Sep 17 00:00:00 2001 From: KnorpelSenf Date: Sat, 22 Jun 2024 00:07:09 +0200 Subject: [PATCH 2/2] test: add test for ctx.chatId in callback queries --- test/composer.type.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/composer.type.test.ts b/test/composer.type.test.ts index 43909f85..675c4c7e 100644 --- a/test/composer.type.test.ts +++ b/test/composer.type.test.ts @@ -60,6 +60,7 @@ describe("Composer types", () => { const callbackQueryMessage = ctx.callbackQuery.message; const callbackQueryData = ctx.callbackQuery.data; const match = ctx.match; + const chatId = ctx.chatId; assertType< IsExact >( @@ -92,6 +93,7 @@ describe("Composer types", () => { assertType>( true, ); + assertType>(true); }); }); }); @@ -311,4 +313,15 @@ describe("Composer types", () => { }); }); }); + + describe("known combined usages", () => { + it("should work with .chatType.callbackQuery", () => { + composer.chatType("private").callbackQuery("query", (ctx) => { + assertType>(true); + }); + composer.callbackQuery("query").chatType("private", (ctx) => { + assertType>(true); + }); + }); + }); });