Conflicting data types with isMessageInstance()

src/commands/ping.ts:18:31 - error TS2345: Argument of type 'APIMessage | Message<boolean>' is not assignable to parameter of type 'Message<boolean> | APIMessage'.
Solution:
Framework does however but I can assure you the code or does are not the issue here otherwise far more people than just you would be having problems.
Jump to solution
7 Replies
JcbSm
JcbSmOP2y ago
This could just be me being stilly, but am I forgetting something important Don't want to hard cast msg But I don't see how type X | Y != type Y | X I ran into this error following the guide
JcbSm
JcbSmOP2y ago
am I not? import { isMessageInstance } from "@sapphire/discord.js-utilities"; this is my only import from anythign other than the framework
Favna
Favna2y ago
then use it properly kekw
if (isMessageInstance(message)) {
// only here it will be Message<boolean>
}

// and here it will be APIMessage
if (isMessageInstance(message)) {
// only here it will be Message<boolean>
}

// and here it will be APIMessage
oh wait I misread your message dedupe your dependencies and make sure you havent installed discord-api-types yourself, or do not install a version newer than 0.33.5
JcbSm
JcbSmOP2y ago
"dependencies": {
"@sapphire/discord.js-utilities": "^5.1.2",
"@sapphire/framework": "^3.1.4",
"@sapphire/ts-config": "^3.3.4",
"discord.js": "^13.12.0",
"dotenv": "^16.0.3",
"mysql": "^2.18.1"
},
"devDependencies": {
"@types/mysql": "^2.15.21"
},
"dependencies": {
"@sapphire/discord.js-utilities": "^5.1.2",
"@sapphire/framework": "^3.1.4",
"@sapphire/ts-config": "^3.3.4",
"discord.js": "^13.12.0",
"dotenv": "^16.0.3",
"mysql": "^2.18.1"
},
"devDependencies": {
"@types/mysql": "^2.15.21"
},
Dependencies seem ok oh oh I see i see i need to delete /node_modules/ and reinstall Hmm, still seems to be conflicting Here's the full error if it helps at all
src/commands/ping.ts:19:31 - error TS2345: Argument of type 'APIMessage | Message<boolean>' is not assignable to parameter of type 'Message<boolean> | APIMessage'.
Type 'APIMessage' is not assignable to type 'Message<boolean> | APIMessage'.
Type 'import("C:/Users/jacob/Documents/GitHub/THE-PRISM-V4/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/channel").APIMessage' is not assignable to type 'import("C:/Users/jacob/Documents/GitHub/THE-PRISM-V4/node_modules/discord-api-types/payloads/v9/channel").APIMessage'.
The types of 'author.flags' are incompatible between these types.
Type 'import("C:/Users/jacob/Documents/GitHub/THE-PRISM-V4/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/user").UserFlags | undefined' is not assignable to type 'import("C:/Users/jacob/Documents/GitHub/THE-PRISM-V4/node_modules/discord-api-types/payloads/v9/user").UserFlags | undefined'.
Type 'import("C:/Users/jacob/Documents/GitHub/THE-PRISM-V4/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/user").UserFlags' is not assignable to type 'UserFlags'.

19 if (isMessageInstance(msg)) {
~~~
src/commands/ping.ts:19:31 - error TS2345: Argument of type 'APIMessage | Message<boolean>' is not assignable to parameter of type 'Message<boolean> | APIMessage'.
Type 'APIMessage' is not assignable to type 'Message<boolean> | APIMessage'.
Type 'import("C:/Users/jacob/Documents/GitHub/THE-PRISM-V4/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/channel").APIMessage' is not assignable to type 'import("C:/Users/jacob/Documents/GitHub/THE-PRISM-V4/node_modules/discord-api-types/payloads/v9/channel").APIMessage'.
The types of 'author.flags' are incompatible between these types.
Type 'import("C:/Users/jacob/Documents/GitHub/THE-PRISM-V4/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/user").UserFlags | undefined' is not assignable to type 'import("C:/Users/jacob/Documents/GitHub/THE-PRISM-V4/node_modules/discord-api-types/payloads/v9/user").UserFlags | undefined'.
Type 'import("C:/Users/jacob/Documents/GitHub/THE-PRISM-V4/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/user").UserFlags' is not assignable to type 'UserFlags'.

19 if (isMessageInstance(msg)) {
~~~
i haven't manually installed discord-api-types but i deleted /node_modules/ and ran npm install and it's still there Does sapphire djs util install discord-api-types?
Spinel
Spinel2y ago
@sapphire/discord.js-utilities
Discord.js specific utilities for your JavaScript/TypeScript bots ❯ Author: sapphiredev ❯ Maintainers: favna, kyranet, and vladfrangu ❯ Latest version: 5.1.2 ❯ License: MIT ❯ Date Created: <t:1609519287:d> ❯ Date Modified: <t:1670200605:d> Dependencies: @sapphire/discord-utilities, @sapphire/duration, @sapphire/utilities, and tslib
Solution
Favna
Favna2y ago
Framework does however but I can assure you the code or does are not the issue here otherwise far more people than just you would be having problems.
Want results from more Discord servers?
Add your server