Property 'commands' does not exist even after module augmentation

TypeScript DJS V14 Hi there, I'm doing
client.commands = new Collection()

const commandsPath = path.join(__dirname, "commands")
// eslint-disable-next-line security/detect-non-literal-fs-filename
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".ts"))

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file)
// eslint-disable-next-line @typescript-eslint/no-var-requires, security/detect-non-literal-require
const command = require(filePath)
client.commands.set(command.data.name, command)
}
client.commands = new Collection()

const commandsPath = path.join(__dirname, "commands")
// eslint-disable-next-line security/detect-non-literal-fs-filename
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".ts"))

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file)
// eslint-disable-next-line @typescript-eslint/no-var-requires, security/detect-non-literal-require
const command = require(filePath)
client.commands.set(command.data.name, command)
}
in my index.ts and I have
import { Collection } from "discord.js"

declare module "discord.js" {
export interface Client {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
commands: Collection<unknown, any>
}
}
import { Collection } from "discord.js"

declare module "discord.js" {
export interface Client {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
commands: Collection<unknown, any>
}
}
in /types/common/discord.d.ts however im still getting Property 'commands' does not exist on type 'Client<boolean>'. when trying to compile. DJS v14.2.0 NODE v16.10.0
12 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
net-tech-
net-tech-OP3y ago
yes already done
souji
souji3y ago
cannot reproduce works as expected with exactly that augmentation on 14.2
net-tech-
net-tech-OP3y ago
what es version are you targeting, im doing es2021
souji
souji3y ago
2021
net-tech-
net-tech-OP3y ago
im targeting es2021 wtf thats weird so after only doing tsc it seems to work, i was running ts-node index.ts before
souji
souji3y ago
never used that, no idea
net-tech-
net-tech-OP3y ago
thank you either way
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
net-tech-
net-tech-OP2y ago
changing to file.endsWith(".js"), compiling with tsc and running compiled code never used ts-node again
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
net-tech-
net-tech-OP2y ago
so i would suggest setting an outDir in your tsconfig to something like dist so that the compiled files go into a folder called dist and then after compiling you can run node on the compiled main file
Want results from more Discord servers?
Add your server