#Switching from JS to TS
15 messages · Page 1 of 1 (latest)
- 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!
- Create a tsconfig.json
- Rename all files to ts
- Change all commonjs to esm in case you switched
- Go through each file and resolve any errors
okay so
wdym change all commonjs to esm
and uh what are all thew new things that ts offers (like ive heard of classes or constructors or something like that)
classes and constructors are basic javascript
hm
what about those thingies that you add when defning a variable in ts? usually enclosed in <>
that's called generics
what are they
Use to give types to a variable or function
For the most part
you should probably go through the ts official handbook before switching
oh that's neat
i'll go through it then
@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.