Types for discord.js with TypeScript

So, I've tried to install @types/discord.js, however I get a 404 error. Where can I find types for discord.js?
17 Replies
megatank58
megatank583y ago
The types are shipped with discord.js inbuilt discord.js provides full typescript support by default/on install
Grif
Grif3y ago
Oh, so do I need to import them or? For example when defining a client:
import { Client } from "discord.js"

const client: Client = new Client({something: "a"})
import { Client } from "discord.js"

const client: Client = new Client({something: "a"})
Can I just do it like that? The {something: "a"} part gives me an error because it isn't a client option, so I guess that's correct?
megatank58
megatank583y ago
yes something: "a" is not an option but intents are
d.js docs
d.js docs3y ago
• Websocket intents limit events and decrease memory usage: learn more • See what intents you need here
Grif
Grif3y ago
Right! Thank you a lot! Just starting with TypeScript and this looks very cool! Also, is there a place where I can find all types in discord.js, for example in the ready event? Nvm found it
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grif
Grif3y ago
on top of every file or just the index one?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
megatank58
megatank583y ago
this is incorrect, it imports discord.js with the name all
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grif
Grif3y ago
I'll deffinitely refer to this later, but since I'm just starting with TS, I'll import needed types at the top of the file when I need them
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grif
Grif3y ago
:)
Grif
Grif3y ago
Also, for anyone else looking at this in the future, just discovered there is a blue TS icon (picture above) on the npm site, when a library has built-in TS declarations.
souji
souji3y ago
i don't see the reason for that that's considered best practice anyways
monbrey
monbrey3y ago
The answer is the docs
monbrey
monbrey3y ago
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.