Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal Type Error in Composer #2011

Open
sharpvik opened this issue Jul 18, 2024 · 3 comments
Open

Internal Type Error in Composer #2011

sharpvik opened this issue Jul 18, 2024 · 3 comments

Comments

@sharpvik
Copy link

Context

I am using Telegraf in a firebase cloud function with roughly the following setup:

new Telegraf(TELEGRAM_BOT_TOKEN.value())
      .handleUpdate(request.body, response)
      .then(() => response.sendStatus(200));
  • Telegraf.js Version: 4.16.3
  • Node.js Version: 21.7.3
  • Operating System: MacOS

Minimal Example Code Reproducing the Issue

The issue isn't about my code really. When I try to

npm run serve

my Firebase cloud functions, it fails at the

tsc build

with an internal type error (provided below).

Expected Behavior

I want the thing to compile and run.

Current Behavior

It fails to compile because of some internal type mismatch errors.

Error Message and Logs (export DEBUG='telegraf:*')

node_modules/telegraf/typings/composer.d.ts:39:129 - error TS2344: Type 'FilteredContext<C, Filter>' does not satisfy the constraint 'Context<Update>'.
  Type 'NarrowedContext<C, Extract<MessageReactionUpdate, Record<Filter, object>> | Extract<MessageReactionCountUpdate, Record<...>> | ... 15 more ... | Extract<...>> | NarrowedContext<...>' is not assignable to type 'Context<Update>'.
    Type 'NarrowedContext<C, Extract<MessageReactionUpdate, Record<Filter, object>> | Extract<MessageReactionCountUpdate, Record<...>> | ... 15 more ... | Extract<...>>' is not assignable to type 'Context<Update>'.
      Types of property 'message' are incompatible.
        Type 'PropOr<Extract<MessageReactionUpdate, Record<Filter, object>>, "message", undefined> | PropOr<Extract<MessageReactionCountUpdate, Record<...>>, "message", undefined> | ... 15 more ... | PropOr<...>' is not assignable to type '(New & NonChannel & Message) | undefined'.
          Type 'PropOr<Extract<MessageReactionUpdate, Record<Filter, object>>, "message", undefined>' is not assignable to type '(New & NonChannel & Message) | undefined'.
            Type '(Partial<Record<"message", unknown>> & Extract<MessageReactionUpdate, Record<Filter, object>>)["message"] | undefined' is not assignable to type '(New & NonChannel & Message) | undefined'.
              Type 'Extract<MessageReactionUpdate, Record<Filter, object>>["message"]' is not assignable to type '(New & NonChannel & Message) | undefined'.
                Type 'object' is not assignable to type '(New & NonChannel & Message) | undefined'.
                  Type 'Extract<MessageReactionUpdate, Record<Filter, object>>["message"]' is not assignable to type 'New & NonChannel & VoiceMessage'.
                    Type 'object' is not assignable to type 'New & NonChannel & VoiceMessage'.
                      Type 'object' is not assignable to type 'NonChannel'.
                        Type 'Extract<MessageReactionUpdate, Record<Filter, object>>["message"]' is not assignable to type 'NonChannel'.
                          Type '{}' is missing the following properties from type 'NonChannel': chat, from
                            Type 'PropOr<Record<Filter, object> & MessageReactionUpdate, "message", undefined>' is not assignable to type '(New & NonChannel & Message) | undefined'.
                              Type '(Partial<Record<"message", unknown>> & Record<Filter, object> & MessageReactionUpdate)["message"] | undefined' is not assignable to type '(New & NonChannel & Message) | undefined'.
                                Type 'object' is not assignable to type '(New & NonChannel & Message) | undefined'.
                                  Type 'PropOr<Record<Filter, object> & MessageReactionUpdate, "message", undefined>' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                    Type 'PropOr<Extract<MessageReactionUpdate, Record<Filter, object>>, "message", undefined>' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                      Type '(Partial<Record<"message", unknown>> & Extract<MessageReactionUpdate, Record<Filter, object>>)["message"] | undefined' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                        Type 'undefined' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                          Type 'PropOr<Record<Filter, object> & MessageReactionUpdate, "message", undefined>' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                            Type '(Partial<Record<"message", unknown>> & Record<Filter, object> & MessageReactionUpdate)["message"] | undefined' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                              Type 'undefined' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                                Type 'PropOr<Record<Filter, object> & MessageReactionUpdate, "message", undefined>' is not assignable to type 'New'.
                                                  Type '(Partial<Record<"message", unknown>> & Record<Filter, object> & MessageReactionUpdate)["message"] | undefined' is not assignable to type 'New'.
                                                    Type 'undefined' is not assignable to type 'New'.
                                                      Type 'PropOr<Extract<MessageReactionUpdate, Record<Filter, object>>, "message", undefined>' is not assignable to type 'New'.
                                                        Type '(Partial<Record<"message", unknown>> & Extract<MessageReactionUpdate, Record<Filter, object>>)["message"] | undefined' is not assignable to type 'New'.
                                                          Type 'undefined' is not assignable to type 'New'.
                                                            Type 'PropOr<Record<Filter, object> & MessageReactionUpdate, "message", undefined>' is not assignable to type 'New'.
                                                              Type '(Partial<Record<"message", unknown>> & Record<Filter, object> & MessageReactionUpdate)["message"] | undefined' is not assignable to type 'New'.
                                                                Type 'undefined' is not assignable to type 'New'.
                                                                  Type 'NarrowedContext<C, MessageUpdate<Message>> | NarrowedContext<C, PollUpdate> | NarrowedContext<C, ChatMemberUpdate> | ... 15 more ... | NarrowedContext<...>' is not assignable to type 'Context<Update>'.
                                                                    Type 'NarrowedContext<C, C["update"]>' is not assignable to type 'Context<Update>'.
                                                                      Types of property 'msg' are incompatible.
                                                                        Type 'GetMsg<C["update"]> & Msg' is not assignable to type '(MaybeInaccessibleMessage | (New & NonChannel & Message) | (New & Channel & Message) | (Edited & Channel & CommonMessageBundle) | (Edited & ... 1 more ... & CommonMessageBundle) | undefined) & Msg'.
                                                                          Type 'GetMsg<C["update"]> & Msg' is not assignable to type 'Edited & NonChannel & VoiceMessage & Msg'.
                                                                            Type 'GetMsg<C["update"]> & Msg' is not assignable to type 'Edited'.

39     on<Filter extends tt.UpdateType | Guard<C['update']>>(filters: MaybeArray<Filter>, ...fns: NonemptyReadonlyArray<Middleware<FilteredContext<C, Filter>>>): this;
                                                                                                                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/telegraf/typings/composer.d.ts:152:159 - error TS2344: Type 'FilteredContext<Ctx, Filter>' does not satisfy the constraint 'Context<Update>'.
  Type 'NarrowedContext<Ctx, Extract<MessageReactionUpdate, Record<Filter, object>> | Extract<MessageReactionCountUpdate, Record<...>> | ... 15 more ... | Extract<...>> | NarrowedContext<...>' is not assignable to type 'Context<Update>'.
    Type 'NarrowedContext<Ctx, Extract<MessageReactionUpdate, Record<Filter, object>> | Extract<MessageReactionCountUpdate, Record<...>> | ... 15 more ... | Extract<...>>' is not assignable to type 'Context<Update>'.
      Types of property 'message' are incompatible.
        Type 'PropOr<Extract<MessageReactionUpdate, Record<Filter, object>>, "message", undefined> | PropOr<Extract<MessageReactionCountUpdate, Record<...>>, "message", undefined> | ... 15 more ... | PropOr<...>' is not assignable to type '(New & NonChannel & Message) | undefined'.
          Type 'PropOr<Extract<MessageReactionUpdate, Record<Filter, object>>, "message", undefined>' is not assignable to type '(New & NonChannel & Message) | undefined'.
            Type '(Partial<Record<"message", unknown>> & Extract<MessageReactionUpdate, Record<Filter, object>>)["message"] | undefined' is not assignable to type '(New & NonChannel & Message) | undefined'.
              Type 'Extract<MessageReactionUpdate, Record<Filter, object>>["message"]' is not assignable to type '(New & NonChannel & Message) | undefined'.
                Type 'object' is not assignable to type '(New & NonChannel & Message) | undefined'.
                  Type 'Extract<MessageReactionUpdate, Record<Filter, object>>["message"]' is not assignable to type 'New & NonChannel & VoiceMessage'.
                    Type 'object' is not assignable to type 'New & NonChannel & VoiceMessage'.
                      Type 'Extract<MessageReactionUpdate, Record<Filter, object>>["message"]' is not assignable to type 'NonChannel'.
                        Type 'object' is not assignable to type 'NonChannel'.
                          Type 'PropOr<Record<Filter, object> & MessageReactionUpdate, "message", undefined>' is not assignable to type '(New & NonChannel & Message) | undefined'.
                            Type '(Partial<Record<"message", unknown>> & Record<Filter, object> & MessageReactionUpdate)["message"] | undefined' is not assignable to type '(New & NonChannel & Message) | undefined'.
                              Type 'object' is not assignable to type '(New & NonChannel & Message) | undefined'.
                                Type 'PropOr<Record<Filter, object> & MessageReactionUpdate, "message", undefined>' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                  Type 'PropOr<Extract<MessageReactionUpdate, Record<Filter, object>>, "message", undefined>' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                    Type '(Partial<Record<"message", unknown>> & Extract<MessageReactionUpdate, Record<Filter, object>>)["message"] | undefined' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                      Type 'undefined' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                        Type 'PropOr<Record<Filter, object> & MessageReactionUpdate, "message", undefined>' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                          Type '(Partial<Record<"message", unknown>> & Record<Filter, object> & MessageReactionUpdate)["message"] | undefined' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                            Type 'undefined' is not assignable to type 'New & NonChannel & VoiceMessage'.
                                              Type 'PropOr<Record<Filter, object> & MessageReactionUpdate, "message", undefined>' is not assignable to type 'New'.
                                                Type '(Partial<Record<"message", unknown>> & Record<Filter, object> & MessageReactionUpdate)["message"] | undefined' is not assignable to type 'New'.
                                                  Type 'undefined' is not assignable to type 'New'.
                                                    Type 'PropOr<Extract<MessageReactionUpdate, Record<Filter, object>>, "message", undefined>' is not assignable to type 'New'.
                                                      Type '(Partial<Record<"message", unknown>> & Extract<MessageReactionUpdate, Record<Filter, object>>)["message"] | undefined' is not assignable to type 'New'.
                                                        Type 'undefined' is not assignable to type 'New'.
                                                          Type 'PropOr<Record<Filter, object> & MessageReactionUpdate, "message", undefined>' is not assignable to type 'New'.
                                                            Type '(Partial<Record<"message", unknown>> & Record<Filter, object> & MessageReactionUpdate)["message"] | undefined' is not assignable to type 'New'.
                                                              Type 'undefined' is not assignable to type 'New'.
                                                                Type 'NarrowedContext<Ctx, MessageUpdate<Message>> | NarrowedContext<Ctx, PollUpdate> | NarrowedContext<...> | ... 15 more ... | NarrowedContext<...>' is not assignable to type 'Context<Update>'.
                                                                  Type 'NarrowedContext<Ctx, Ctx["update"]>' is not assignable to type 'Context<Update>'.
                                                                    Types of property 'msg' are incompatible.
                                                                      Type 'GetMsg<Ctx["update"]> & Msg' is not assignable to type '(MaybeInaccessibleMessage | (New & NonChannel & Message) | (New & Channel & Message) | (Edited & Channel & CommonMessageBundle) | (Edited & ... 1 more ... & CommonMessageBundle) | undefined) & Msg'.
                                                                        Type 'GetMsg<Ctx["update"]> & Msg' is not assignable to type 'Edited & NonChannel & VoiceMessage & Msg'.
                                                                          Type 'GetMsg<Ctx["update"]> & Msg' is not assignable to type 'Edited'.

152     static on<Ctx extends Context, Filter extends tt.UpdateType | Guard<Ctx['update']>>(filters: MaybeArray<Filter>, ...fns: NonemptyReadonlyArray<Middleware<FilteredContext<Ctx, Filter>>>): MiddlewareFn<Ctx>;
                                                                                                                                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@MKRhere
Copy link
Member

MKRhere commented Jul 19, 2024

TypeScript version? Regardless, it's better to enable skipLibCheck: true in your tsconfig.json. It's recommended, and is the default setting if you did tsc init

@sharpvik
Copy link
Author

TypeScript version?

I'm not sure, @MKRhere. Is there a special way to install Telegraf for TS?

I just hit npm i telegraf

@spokik
Copy link

spokik commented Jul 31, 2024

TypeScript version? Regardless, it's better to enable skipLibCheck: true in your tsconfig.json. It's recommended, and is the default setting if you did tsc init

Thanks, it helped me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants