I am new to Typescript and I am trying to convert my Js code to ts
I have the base bot set up already in Javascript like the command handling and the main file and when I asked if I could use Typescript with my bot they said It should just work fine if I convert my code. When I did this I found out I needed a tsconfig.json and now I was getting a lot of Include and Exclude errors etc. I just use the basic one could somebody help me
tsc --init
Its in my root directory and my main is in Root/src/bot.ts. Just somebody help me set it up.9 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- 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!Could you help me with this
can do it with bun js
Bun
Module resolution – Runtime | Bun Docs
Bun uses ESM and implements an extended version of the Node.js module resolution algorithm.
So you are using bun?
You shouldn’t be running w/ node.js if you are
Could somebody help me resolve this other Issue I am having.
After translating all of my code/Handlers etc and using the typescript compiler its saying require isn't a function is this because I need to use import in my ts file??
My code snippet:
https://gist.github.com/Ceymikey/4173d428ace844fd257feff1c94a13c9
Gist
The main file for my Discord ts bot
The main file for my Discord ts bot. GitHub Gist: instantly share code, notes, and snippets.
My compiled js file is just a bunch of code for nodejs shouldn;t be anything to worry about
I've also put it in the same folder to not get any path not found conflicts
(Both in src folder)
Nope
If you meant me.
I tried to find a way with import but I don't know how it could be done
But do I just completely remove the (client)
Wait let me reopen my code before I start talking
I tried this
But there seems to be a mistake in my code still.
Than I remove (client) from the end
And now I am resolving other issues. Should I be worried about this?
It was showing red and saying An argument for evenfiles was not provided
Alright
Is this because I had set my module to
ES6
When I switched everything I got like 15 more errors but await was working
v20.2.0
Do you recommend upgrading to v21+
Or what module should I use
With what target
I use es2022 as a target right now. i am facing other issues now with the ts compiler.
I am sure the path is correct but just to be sure.
My code: https://gist.github.com/Ceymikey/05625bbe4077fb3e9f82d0306cccdffb
Tsc Javascript code: https://gist.github.com/Ceymikey/6978485d4c3723616812f2f5d9a5b206
Also just to clear up some things.
I used the require function because I changed my exports default
to a module.exports
in my handleEvents.
And here is my path
Was I support to require my handleEvents.js
that came out of the tsc or my handleEvents.ts
?
Oh oke I was thinking it would conflict my paths if I did that.
I thought the tsc only converts code to js that node understands and doesn't change anything.
Its giving me that same error tho:
Its in my Utils folder
So your telling me I was instead of the dist or test folder suppost to put it in the same folder as my bot.ts?
So in utils
Error: Cannot find module './src/functions/handleCommands.ts'
This is from bot.js
fixing paths in my code
I am really just starting to think Typescript is messing up my paths
Because in my ts code I did them correct
And they are both the same
Idk what I am doing wrong
¯\_(ツ)_/¯
I compile my code and run the js cuz node cannot directly run ts code.
Found it I think
As you said I was pointing all to my src folder ts files but now bot.ts its functions etc is pointing to src and my bot.js is pointing to all the stuff inside of my dist folder.
Handling js in dist handling ts in dist starting succesfully
But isn't doing anything
No console log events
No slash commands
So ig I still messed up some path
It was because it stated endswith .ts and not .js is there a way for me to make it so that the tsc also changes that
So when I compile it .ts changes to .js
Or could I use something like .*
Its in my main file