#Switching from JS to TS

15 messages · Page 1 of 1 (latest)

spare salmon
#

Hello,
I have been thinking of switching from JS to TS lately (including my DJS projects), but I don't know where to start. Any help?

amber riverBOT
#
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
swift flax
#
  1. Create a tsconfig.json
  2. Rename all files to ts
  3. Change all commonjs to esm in case you switched
  4. Go through each file and resolve any errors
spare salmon
swift flax
#

classes and constructors are basic javascript

spare salmon
#

hm

spare salmon
swift flax
#

that's called generics

spare salmon
#

what are they

vapid field
#

Use to give types to a variable or function

#

For the most part

swift flax
spare salmon
#

oh that's neat

#

i'll go through it then

sinful cairn
#

@spare salmon If you just want better intellisense you can just add jsdoc to all of ur functions.
I heard some big tech stuff are just doing that instead of typescript
typescript can get a bit annoying if you lets say want to add a new property to the instance of a class, typescript will show an error that that property doesn't exist in that type so you have to extend the namespace and it gets really annoying if you have a lot of those instances in your code.

an example would be adding a commands collection to your discorc Client instance.
Typescript won't let you do that unless you extend the Client interface

or lets say you have a helper function that returns an object with some parameters, like maybe an embed description and title, then you want to add a title to it in another function, but it won't let you do that because "title" isn't a property of the return type of your helper function.