discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.39k stars 3.97k forks source link

.ts to .js loses class attributes? #5790

Closed VadneyK closed 3 years ago

VadneyK commented 3 years ago

Please describe the problem you are having in as much detail as possible: I am writing a discord bot in typescript, heavily influenced by the tutorial here and am just typing things to make it fit in .ts instead of .js. I am having issues where converting .ts classes to .js classes makes class attributes in .ts dissapear. cross-posted details here: https://github.com/PlasmNetwork/dusty-faucet/issues/3#issuecomment-857844417

Is this a known issue and therefore Commando should be used instead or discord.ts should be used instead since transpiling from ts to js causes issues?

I understand this may not be related enough to discord.js since it seems to be a ts to js transpiling detail, so please feel free to point me to a better place to post this!

Include a reproducible code sample here, if possible: code mentioned in screenshot at cross-post is here: https://github.com/PlasmNetwork/dusty-faucet/tree/main/app

Further details:

discord.js@^12.5.1: node - v16.2.0 MacOS M1 chip BigSur 11.2.3 Priority: medium

kyranet commented 3 years ago

Your issue is caused because you're declarig class fields with a type (name: 'drip'), but with no value (name = 'drip'), which results on TS not assigning the values as they're declared but not assigned to any value.


The issue tracker is only for bug reports and enhancement suggestions. If you have a question, please ask it in the Discord server instead of opening an issue – you will get redirected there anyway.

VadneyK commented 3 years ago

Ahh ok was kind of a long question and I didn't want to bombard the chat with all the descriptions.

that seemed to be one of my errors. I thought setting value: 'default' sets value to default in TS and is equivalent to value = 'default' but I guess instead TS thought I made a new type called 'default'?

also it seems like in TS we can immediately access the contents of the object, but even with the : to = change I was still getting undifined attributes so I looked over at the drip.js file and there was a constructor so I added the same constructor to the drip.ts file and called that to get the new object instead of doing the file access with fs.readdirSync from nodejs. I guess the fs.readdirSync works differently in comminJs as in not auto typing the read object?

either way here was my solution for reference:

Screen Shot 2021-06-09 at 2 00 42 PM