From 490a9af7291749f80cfe110f5f06356971d40620 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Sun, 19 Aug 2018 23:56:47 +0200 Subject: [PATCH] node-telegram-bot-api: Fix promise return type The generic type of the Promise should correspond to the non-error return-type of the function. The error is implicitly of type any and is not specified in the Promise generic type. https://stackoverflow.com/a/41079355/284318 --- types/node-telegram-bot-api/index.d.ts | 110 +++++++++--------- .../node-telegram-bot-api-tests.ts | 3 + types/tgfancy/index.d.ts | 8 +- 3 files changed, 62 insertions(+), 59 deletions(-) diff --git a/types/node-telegram-bot-api/index.d.ts b/types/node-telegram-bot-api/index.d.ts index 32f4ae8d85..934daa3fe3 100644 --- a/types/node-telegram-bot-api/index.d.ts +++ b/types/node-telegram-bot-api/index.d.ts @@ -904,96 +904,96 @@ declare class TelegramBot extends EventEmitter { hasOpenWebHook(): boolean; - getMe(): Promise; + getMe(): Promise; setWebHook(url: string, options?: TelegramBot.SetWebHookOptions): Promise; - deleteWebHook(): Promise; + deleteWebHook(): Promise; - getWebHookInfo(): Promise; + getWebHookInfo(): Promise; - getUpdates(options?: TelegramBot.GetUpdatesOptions): Promise; + getUpdates(options?: TelegramBot.GetUpdatesOptions): Promise; processUpdate(update: TelegramBot.Update): void; - sendMessage(chatId: number | string, text: string, options?: TelegramBot.SendMessageOptions): Promise; + sendMessage(chatId: number | string, text: string, options?: TelegramBot.SendMessageOptions): Promise; - answerInlineQuery(inlineQueryId: string, results: ReadonlyArray, options?: TelegramBot.AnswerInlineQueryOptions): Promise; + answerInlineQuery(inlineQueryId: string, results: ReadonlyArray, options?: TelegramBot.AnswerInlineQueryOptions): Promise; - forwardMessage(chatId: number | string, fromChatId: number | string, messageId: number | string, options?: TelegramBot.ForwardMessageOptions): Promise; + forwardMessage(chatId: number | string, fromChatId: number | string, messageId: number | string, options?: TelegramBot.ForwardMessageOptions): Promise; - sendPhoto(chatId: number | string, photo: string | Stream | Buffer, options?: TelegramBot.SendPhotoOptions): Promise; + sendPhoto(chatId: number | string, photo: string | Stream | Buffer, options?: TelegramBot.SendPhotoOptions): Promise; - sendAudio(chatId: number | string, audio: string | Stream | Buffer, options?: TelegramBot.SendAudioOptions): Promise; + sendAudio(chatId: number | string, audio: string | Stream | Buffer, options?: TelegramBot.SendAudioOptions): Promise; - sendDocument(chatId: number | string, doc: string | Stream | Buffer, options?: TelegramBot.SendDocumentOptions, fileOpts?: any): Promise; + sendDocument(chatId: number | string, doc: string | Stream | Buffer, options?: TelegramBot.SendDocumentOptions, fileOpts?: any): Promise; - sendMediaGroup(chatId: number | string, media: ReadonlyArray, options?: TelegramBot.SendMediaGroupOptions): Promise; + sendMediaGroup(chatId: number | string, media: ReadonlyArray, options?: TelegramBot.SendMediaGroupOptions): Promise; - sendSticker(chatId: number | string, sticker: string | Stream | Buffer, options?: TelegramBot.SendStickerOptions): Promise; + sendSticker(chatId: number | string, sticker: string | Stream | Buffer, options?: TelegramBot.SendStickerOptions): Promise; - sendVideo(chatId: number | string, video: string | Stream | Buffer, options?: TelegramBot.SendVideoOptions): Promise; + sendVideo(chatId: number | string, video: string | Stream | Buffer, options?: TelegramBot.SendVideoOptions): Promise; - sendVideoNote(chatId: number | string, videoNote: string | Stream | Buffer, options?: TelegramBot.SendVideoNoteOptions): Promise; + sendVideoNote(chatId: number | string, videoNote: string | Stream | Buffer, options?: TelegramBot.SendVideoNoteOptions): Promise; - sendVoice(chatId: number | string, voice: string | Stream | Buffer, options?: TelegramBot.SendVoiceOptions): Promise; + sendVoice(chatId: number | string, voice: string | Stream | Buffer, options?: TelegramBot.SendVoiceOptions): Promise; - sendChatAction(chatId: number | string, action: TelegramBot.ChatAction): Promise; + sendChatAction(chatId: number | string, action: TelegramBot.ChatAction): Promise; - kickChatMember(chatId: number | string, userId: string): Promise; + kickChatMember(chatId: number | string, userId: string): Promise; - unbanChatMember(chatId: number | string, userId: string): Promise; + unbanChatMember(chatId: number | string, userId: string): Promise; - restrictChatMember(chatId: number | string, userId: string, options?: TelegramBot.RestrictChatMemberOptions): Promise; + restrictChatMember(chatId: number | string, userId: string, options?: TelegramBot.RestrictChatMemberOptions): Promise; - promoteChatMember(chatId: number | string, userId: string, options?: TelegramBot.PromoteChatMemberOptions): Promise; + promoteChatMember(chatId: number | string, userId: string, options?: TelegramBot.PromoteChatMemberOptions): Promise; - exportChatInviteLink(chatId: number | string): Promise; + exportChatInviteLink(chatId: number | string): Promise; - setChatPhoto(chatId: number | string, photo: string | Stream | Buffer): Promise; + setChatPhoto(chatId: number | string, photo: string | Stream | Buffer): Promise; - deleteChatPhoto(chatId: number | string): Promise; + deleteChatPhoto(chatId: number | string): Promise; - setChatTitle(chatId: number | string, title: string): Promise; + setChatTitle(chatId: number | string, title: string): Promise; - setChatDescription(chatId: number | string, description: string): Promise; + setChatDescription(chatId: number | string, description: string): Promise; - pinChatMessage(chatId: number | string, messageId: string): Promise; + pinChatMessage(chatId: number | string, messageId: string): Promise; - unpinChatMessage(chatId: number | string): Promise; + unpinChatMessage(chatId: number | string): Promise; - answerCallbackQuery(callbackQueryId: string, options?: Partial): Promise; + answerCallbackQuery(callbackQueryId: string, options?: Partial): Promise; /** * @deprecated since version 0.30.0 */ - answerCallbackQuery(options?: TelegramBot.AnswerCallbackQueryOptions): Promise; + answerCallbackQuery(options?: TelegramBot.AnswerCallbackQueryOptions): Promise; - editMessageText(text: string, options?: TelegramBot.EditMessageTextOptions): Promise; + editMessageText(text: string, options?: TelegramBot.EditMessageTextOptions): Promise; - editMessageCaption(caption: string, options?: TelegramBot.EditMessageCaptionOptions): Promise; + editMessageCaption(caption: string, options?: TelegramBot.EditMessageCaptionOptions): Promise; - editMessageReplyMarkup(replyMarkup: TelegramBot.InlineKeyboardMarkup, options?: TelegramBot.EditMessageReplyMarkupOptions): Promise; + editMessageReplyMarkup(replyMarkup: TelegramBot.InlineKeyboardMarkup, options?: TelegramBot.EditMessageReplyMarkupOptions): Promise; - getUserProfilePhotos(userId: number | string, options?: TelegramBot.GetUserProfilePhotosOptions): Promise; + getUserProfilePhotos(userId: number | string, options?: TelegramBot.GetUserProfilePhotosOptions): Promise; - sendLocation(chatId: number | string, latitude: number, longitude: number, options?: TelegramBot.SendLocationOptions): Promise; + sendLocation(chatId: number | string, latitude: number, longitude: number, options?: TelegramBot.SendLocationOptions): Promise; - editMessageLiveLocation(latitude: number, longitude: number, options?: TelegramBot.EditMessageLiveLocationOptions): Promise; + editMessageLiveLocation(latitude: number, longitude: number, options?: TelegramBot.EditMessageLiveLocationOptions): Promise; - stopMessageLiveLocation(options?: TelegramBot.StopMessageLiveLocationOptions): Promise; + stopMessageLiveLocation(options?: TelegramBot.StopMessageLiveLocationOptions): Promise; - sendVenue(chatId: number | string, latitude: number, longitude: number, title: string, address: string, options?: TelegramBot.SendVenueOptions): Promise; + sendVenue(chatId: number | string, latitude: number, longitude: number, title: string, address: string, options?: TelegramBot.SendVenueOptions): Promise; - sendContact(chatId: number | string, phoneNumber: string, firstName: string, options?: TelegramBot.SendContactOptions): Promise; + sendContact(chatId: number | string, phoneNumber: string, firstName: string, options?: TelegramBot.SendContactOptions): Promise; - getFile(fileId: string): Promise; + getFile(fileId: string): Promise; - getFileLink(fileId: string): Promise; + getFileLink(fileId: string): Promise; getFileStream(fileId: string): Readable; - downloadFile(fileId: string, downloadDir: string): Promise; + downloadFile(fileId: string, downloadDir: string): Promise; onText(regexp: RegExp, callback: ((msg: TelegramBot.Message, match: RegExpExecArray | null) => void)): void; @@ -1003,34 +1003,34 @@ declare class TelegramBot extends EventEmitter { removeReplyListener(replyListenerId: number): TelegramBot.ReplyListener; - getChat(chatId: number | string): Promise; + getChat(chatId: number | string): Promise; - getChatAdministrators(chatId: number | string): Promise; + getChatAdministrators(chatId: number | string): Promise; - getChatMembersCount(chatId: number | string): Promise; + getChatMembersCount(chatId: number | string): Promise; - getChatMember(chatId: number | string, userId: string): Promise; + getChatMember(chatId: number | string, userId: string): Promise; - leaveChat(chatId: number | string): Promise; + leaveChat(chatId: number | string): Promise; - setChatStickerSet(chatId: number | string, stickerSetName: string): Promise; + setChatStickerSet(chatId: number | string, stickerSetName: string): Promise; - deleteChatStickerSet(chatId: number | string): Promise; + deleteChatStickerSet(chatId: number | string): Promise; - sendGame(chatId: number | string, gameShortName: string, options?: TelegramBot.SendGameOptions): Promise; + sendGame(chatId: number | string, gameShortName: string, options?: TelegramBot.SendGameOptions): Promise; - setGameScore(userId: string, score: number, options?: TelegramBot.SetGameScoreOptions): Promise; + setGameScore(userId: string, score: number, options?: TelegramBot.SetGameScoreOptions): Promise; - getGameHighScores(userId: string, options?: TelegramBot.GetGameHighScoresOptions): Promise; + getGameHighScores(userId: string, options?: TelegramBot.GetGameHighScoresOptions): Promise; - deleteMessage(chatId: number | string, messageId: string, options?: any): Promise; + deleteMessage(chatId: number | string, messageId: string, options?: any): Promise; sendInvoice(chatId: number | string, title: string, description: string, payload: string, providerToken: string, startParameter: string, currency: string, - prices: ReadonlyArray, options?: TelegramBot.SendInvoiceOptions): Promise; + prices: ReadonlyArray, options?: TelegramBot.SendInvoiceOptions): Promise; - answerShippingQuery(shippingQueryId: string, ok: boolean, options?: TelegramBot.AnswerShippingQueryOptions): Promise; + answerShippingQuery(shippingQueryId: string, ok: boolean, options?: TelegramBot.AnswerShippingQueryOptions): Promise; - answerPreCheckoutQuery(preCheckoutQueryId: string, ok: boolean, options?: TelegramBot.AnswerPreCheckoutQueryOptions): Promise; + answerPreCheckoutQuery(preCheckoutQueryId: string, ok: boolean, options?: TelegramBot.AnswerPreCheckoutQueryOptions): Promise; } export = TelegramBot; diff --git a/types/node-telegram-bot-api/node-telegram-bot-api-tests.ts b/types/node-telegram-bot-api/node-telegram-bot-api-tests.ts index b4b09485cb..49368e74ec 100644 --- a/types/node-telegram-bot-api/node-telegram-bot-api-tests.ts +++ b/types/node-telegram-bot-api/node-telegram-bot-api-tests.ts @@ -9,6 +9,9 @@ MyTelegramBot.openWebHook(); MyTelegramBot.closeWebHook(); MyTelegramBot.hasOpenWebHook(); MyTelegramBot.getMe(); +MyTelegramBot.getMe().then((value: TelegramBot.User) => { + const username = value.username; +}); MyTelegramBot.setWebHook('http://typescriptlang.org', {max_connections: 100}); MyTelegramBot.deleteWebHook(); MyTelegramBot.getWebHookInfo(); diff --git a/types/tgfancy/index.d.ts b/types/tgfancy/index.d.ts index a12936e0da..8ff315ee32 100644 --- a/types/tgfancy/index.d.ts +++ b/types/tgfancy/index.d.ts @@ -62,15 +62,15 @@ declare namespace Tgfancy { declare class Tgfancy extends TelegramBot { constructor(token: string, options?: Tgfancy.ConstructorOptions); - resolveChatId(chatId: string): Promise; + resolveChatId(chatId: string): Promise; - openWebSocket(): Promise; + openWebSocket(): Promise; - closeWebSocket(): Promise; + closeWebSocket(): Promise; hasOpenWebSocket(): boolean; - kickChatMember(chatId: number | string, userId: number | string, ban?: boolean): Promise; + kickChatMember(chatId: number | string, userId: number | string, ban?: boolean): Promise; } export = Tgfancy;