discordjs / guide

The official guide for discord.js, created and maintained by core members of its community.
https://discordjs.guide
MIT License
1.57k stars 2.3k forks source link

Typescript code collections #1121

Open almostSouji opened 2 years ago

almostSouji commented 2 years ago

Is your feature request related to a problem? Please describe.

Some concepts covered in the guide require more attention when using typescript.

Describe the solution you'd like

Toplevel code block collection (above files/in navbar setting) to provide both js and ts code samples

Describe alternatives you've considered

Use the current code block collection element to cover typescript versions of code samples

Additional notes

n/a

bchilcott commented 1 year ago

I can't believe this has been avoided/delayed for so long - first class typescript support should be the standard now. Especially to avoid things like this:

if ('data' in command && 'execute' in command) {
  commands.push(command.data.toJSON());
} else {
  console.log(
    `[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
  );
}
monbrey commented 1 year ago

There's nothing wrong with this, nor should it be avoided in JavaScript code.

We are also going to support TypeScript though

bchilcott commented 1 year ago

@monbrey I'm saying that JavaScript code should be avoided, by pushing TS as the primary/recommended way of doing things in the docs. That way nobody needs to worry about checking for key names on arbitrary objects.

I get that it can be seen as personal preference, but ultimately the docs should be recommending best practices and type safety, and giving the option for JS. Not the other way around.

almostSouji commented 1 year ago

JS is a valid programming language, and often the default for beginners. It is not easy to wrap your head around types when you are starting out, which a large portion of our user base is. Thank you for your concern, but we will stick to JS as a main language for the guide and consider including TypeScript examples or variants where appropriate.