question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript: 'MappedInteractionTypes<Cached>[T]' does not satisfy the constraint 'Interaction<CacheType>'.

See original GitHub issue

Which package is this bug report for?

discord.js

Issue description

Typescript building error:

node_modules/discord.js/typings/index.d.ts:1501:42 - error TS2344: Type 'MappedInteractionTypes<Cached>[T]' does not satisfy the constraint 'ModalSubmitInteraction<CacheType> | MessageComponentInteraction<CacheType>'.
  Type 'MessageComponentInteraction<If<Cached, "cached", CacheType>> | ButtonInteraction<If<Cached, "cached", CacheType>> | SelectMenuInteraction<...> | ModalSubmitInteraction<...>' is not assignable to type 'ModalSubmitInteraction<CacheType> | MessageComponentInteraction<CacheType>'.
    Type 'ButtonInteraction<If<Cached, "cached", CacheType>>' is not assignable to type 'ModalSubmitInteraction<CacheType> | MessageComponentInteraction<CacheType>'.
      Type 'ButtonInteraction<If<Cached, "cached", CacheType>>' is not assignable to type 'MessageComponentInteraction<CacheType>'.
        Type 'MappedInteractionTypes<Cached>[T]' is not assignable to type 'MessageComponentInteraction<CacheType>'.
          Type 'MessageComponentInteraction<If<Cached, "cached", CacheType>> | ButtonInteraction<If<Cached, "cached", CacheType>> | SelectMenuInteraction<...> | ModalSubmitInteraction<...>' is not assignable to type 'MessageComponentInteraction<CacheType>'.
            Type 'ButtonInteraction<If<Cached, "cached", CacheType>>' is not assignable to type 'MessageComponentInteraction<CacheType>'.
              Types of property 'channel' are incompatible.
                Type 'CacheTypeReducer<If<Cached, "cached", CacheType>, GuildTextBasedChannel, GuildTextBasedChannel, GuildTextBasedChannel, TextBasedChannel>' is not assignable to type 'GuildTextBasedChannel'.
                  Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'GuildTextBasedChannel'.
                    Type '[If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'GuildTextBasedChannel'.
                      Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'GuildTextBasedChannel'.
                        Type '[If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'GuildTextBasedChannel'.
                          Type 'DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel' is not assignable to type 'GuildTextBasedChannel'.
                            Type 'DMChannel' is not assignable to type 'GuildTextBasedChannel'.
                              Type 'DMChannel' is not assignable to type 'ThreadChannel'.
                                Type '[If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'ThreadChannel'.
                                  Type 'DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel' is not assignable to type 'ThreadChannel'.
                                    Type 'DMChannel' is missing the following properties from type 'ThreadChannel': archived, archivedAt, archiveTimestamp, _createdTimestamp, and 35 more.
                                      Type '[If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'ThreadChannel'.
                                        Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'ThreadChannel'.
                                          Type 'NewsChannel' is not assignable to type 'ThreadChannel'.
                                            Type 'CacheTypeReducer<If<Cached, "cached", CacheType>, GuildTextBasedChannel, GuildTextBasedChannel, GuildTextBasedChannel, TextBasedChannel>' is not assignable to type 'ThreadChannel'.
                                              Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'ThreadChannel'.
                                                Type 'NewsChannel' is missing the following properties from type 'ThreadChannel': archived, archivedAt, archiveTimestamp, _createdTimestamp, and 23 more.

1501     } & MessageComponentCollectorOptions<MappedInteractionTypes<Cached>[T]>;
                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/discord.js/typings/index.d.ts:1509:49 - error TS2344: Type 'MappedInteractionTypes<Cached>[T]' does not satisfy the constraint 'ModalSubmitInteraction<CacheType> | MessageComponentInteraction<CacheType>'.
  Type 'MessageComponentInteraction<If<Cached, "cached", CacheType>> | ButtonInteraction<If<Cached, "cached", CacheType>> | SelectMenuInteraction<...> | ModalSubmitInteraction<...>' is not assignable to type 'ModalSubmitInteraction<CacheType> | MessageComponentInteraction<CacheType>'.
    Type 'ButtonInteraction<If<Cached, "cached", CacheType>>' is not assignable to type 'ModalSubmitInteraction<CacheType> | MessageComponentInteraction<CacheType>'.
      Type 'ButtonInteraction<If<Cached, "cached", CacheType>>' is not assignable to type 'MessageComponentInteraction<CacheType>'.
        Type 'MappedInteractionTypes<Cached>[T]' is not assignable to type 'MessageComponentInteraction<CacheType>'.
          Type 'MessageComponentInteraction<If<Cached, "cached", CacheType>> | ButtonInteraction<If<Cached, "cached", CacheType>> | SelectMenuInteraction<...> | ModalSubmitInteraction<...>' is not assignable to type 'MessageComponentInteraction<CacheType>'.
            Type 'ButtonInteraction<If<Cached, "cached", CacheType>>' is not assignable to type 'MessageComponentInteraction<CacheType>'.
              Types of property 'channel' are incompatible.
                Type 'CacheTypeReducer<If<Cached, "cached", CacheType>, GuildTextBasedChannel, GuildTextBasedChannel, GuildTextBasedChannel, TextBasedChannel>' is not assignable to type 'GuildTextBasedChannel'.
                  Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'GuildTextBasedChannel'.
                    Type '[If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'GuildTextBasedChannel'.
                      Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'GuildTextBasedChannel'.
                        Type '[If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'GuildTextBasedChannel'.
                          Type 'DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel' is not assignable to type 'GuildTextBasedChannel'.
                            Type '[If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'ThreadChannel'.
                              Type 'DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel' is not assignable to type 'ThreadChannel'.
                                Type '[If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'ThreadChannel'.
                                  Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'ThreadChannel'.
                                    Type 'NewsChannel' is not assignable to type 'ThreadChannel'.
                                      Type 'CacheTypeReducer<If<Cached, "cached", CacheType>, GuildTextBasedChannel, GuildTextBasedChannel, GuildTextBasedChannel, TextBasedChannel>' is not assignable to type 'ThreadChannel'.
                                        Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'ThreadChannel'.
                                          Type 'NewsChannel' is not assignable to type 'ThreadChannel'.

1509     } & MessageChannelComponentCollectorOptions<MappedInteractionTypes<Cached>[T]>;
                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/discord.js/typings/index.d.ts:1516:35 - error TS2344: Type 'MappedInteractionTypes<Cached>[T]' does not satisfy the constraint 'Interaction<CacheType>'.
  Type 'MessageComponentInteraction<If<Cached, "cached", CacheType>> | ButtonInteraction<If<Cached, "cached", CacheType>> | SelectMenuInteraction<...> | ModalSubmitInteraction<...>' is not assignable to type 'Interaction<CacheType>'.
    Type 'MessageComponentInteraction<If<Cached, "cached", CacheType>>' is not assignable to type 'Interaction<CacheType>'.
      Types of property 'channel' are incompatible.
        Type 'CacheTypeReducer<If<Cached, "cached", CacheType>, GuildTextBasedChannel, GuildTextBasedChannel, GuildTextBasedChannel, TextBasedChannel>' is not assignable to type 'GuildTextBasedChannel'.
          Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'GuildTextBasedChannel'.
            Type '[If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'GuildTextBasedChannel'.
              Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'GuildTextBasedChannel'.
                Type '[If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'GuildTextBasedChannel'.
                  Type 'DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel' is not assignable to type 'GuildTextBasedChannel'.
                    Type '[If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'ThreadChannel'.
                      Type 'DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel' is not assignable to type 'ThreadChannel'.
                        Type '[If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'ThreadChannel'.
                          Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'ThreadChannel'.
                            Type 'NewsChannel' is not assignable to type 'ThreadChannel'.
                              Type 'CacheTypeReducer<If<Cached, "cached", CacheType>, GuildTextBasedChannel, GuildTextBasedChannel, GuildTextBasedChannel, TextBasedChannel>' is not assignable to type 'ThreadChannel'.
                                Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'ThreadChannel'.
                                  Type 'NewsChannel' is not assignable to type 'ThreadChannel'.

1516       InteractionCollectorOptions<MappedInteractionTypes<Cached>[T]>,
                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/discord.js/typings/index.d.ts:1591:27 - error TS2344: Type 'MappedInteractionTypes<Cached>[T]' does not satisfy the constraint 'Interaction<CacheType>'.
  Type 'MessageComponentInteraction<If<Cached, "cached", CacheType>> | ButtonInteraction<If<Cached, "cached", CacheType>> | SelectMenuInteraction<...> | ModalSubmitInteraction<...>' is not assignable to type 'Interaction<CacheType>'.
    Type 'MessageComponentInteraction<If<Cached, "cached", CacheType>>' is not assignable to type 'Interaction<CacheType>'.
      Types of property 'channel' are incompatible.
        Type 'CacheTypeReducer<If<Cached, "cached", CacheType>, GuildTextBasedChannel, GuildTextBasedChannel, GuildTextBasedChannel, TextBasedChannel>' is not assignable to type 'GuildTextBasedChannel'.
          Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'GuildTextBasedChannel'.
            Type '[If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'GuildTextBasedChannel'.
              Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'GuildTextBasedChannel'.
                Type '[If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'GuildTextBasedChannel'.
                  Type 'DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel' is not assignable to type 'GuildTextBasedChannel'.
                    Type '[If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'ThreadChannel'.
                      Type 'DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel' is not assignable to type 'ThreadChannel'.
                        Type '[If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel' is not assignable to type 'ThreadChannel'.
                          Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["cached" | "raw"] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'ThreadChannel'.
                            Type 'NewsChannel' is not assignable to type 'ThreadChannel'.
                              Type 'CacheTypeReducer<If<Cached, "cached", CacheType>, GuildTextBasedChannel, GuildTextBasedChannel, GuildTextBasedChannel, TextBasedChannel>' is not assignable to type 'ThreadChannel'.
                                Type 'GuildTextBasedChannel | ([If<Cached, "cached", CacheType>] extends ["raw"] ? GuildTextBasedChannel : [If<Cached, "cached", CacheType>] extends [...] ? GuildTextBasedChannel : TextBasedChannel)' is not assignable to type 'ThreadChannel'.
                                  Type 'NewsChannel' is not assignable to type 'ThreadChannel'.

1591   ): InteractionCollector<MappedInteractionTypes<Cached>[T]>;

Code sample

No response

Package version

discord.js@13.7.0

Node.js version

17.3.0

Operating system

Debian 10

Priority this issue should have

High (immediate attention needed)

Which partials do you have configured?

Not applicable (subpackage bug)

Which gateway intents are you subscribing to?

Not applicable (subpackage bug)

I have tested this issue on a development release

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

18reactions
iCrawlcommented, May 14, 2022

We don’t support running TS without strict mode enabled. And neither should you run it without anyway.

8reactions
goumscommented, May 26, 2022

How so? I’m not entirely sure what you mean by a “legacy” project here but if it is legacy, don’t upgrade the Typescript or discord.js dependecies to later versions where this happens.

I mean sometime, you still need to add features to old code base, and refactoring everything because one dependency is not compatible is troublesome.

And to add to this problem, it works nice when running with tsnode, only when you want to build with tsc it will fail with the above error message. I suspect you have something wrong in your types for this to happens… it doesn’t make sense that a strict project cannot build in a non strict one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: Mapped type does not satisfy the constraint it just ...
So my guess is that this is related to the type-indexing, whatever stores the constraint on T here does not store the same...
Read more >
TypeScript: Type 'T' does not satisfy the constraint '(...args
In order to instantiate a generic type, say ReturnType<T> , with our type parameter, our type parameter must constrained at least as ...
Read more >
Why is my Pick<> failing with "Type does not satisfy the ...
I have a file called ionIcons.ts. It contains a list of var delcarations. export declare var accessibility: string; export declare var…
Read more >
Typescript error "does not satisfy the constraint new" when ...
If you get an error when trying to use InstanceType from typegoose as a parameter to a method in typescript make sure you...
Read more >
Incorrect, "Type does not satisfy the constraint" error when ...
The following code is in fact valid, compiles and runs fine, and is without error in the TypeScript Playground. However, when R# is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found