#I am new to Typescript and I am trying to convert my Js code to ts

23 messages · Page 1 of 1 (latest)

dry hearthBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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!
versed relicBOT
#

To share long code snippets, use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks or files.

bitter hawk
#

Show your errors you get

bitter hawk
#

Either use require and commonjs. Or use import and esm. Don’t mix them both

worn rose
errant light
#

So you are using bun?

#

You shouldn’t be running w/ node.js if you are

bitter hawk
#

Show your functions/handleEvents.ts file. It doesn’t seem to export a function but you try to use it as one

#

Yeah, that uses esm exports so you can’t call it with require

#

import handleEvents from '…' and then do handleEvents(client)🤷‍♂️

#

You do the import at the top, like any other import. And then you just call the function where you currently require and call it in the same line

#

What mistake? How did you come to that conclusion? You might want to await the handleEvents call

bitter hawk
#

Yes. What node version do you intend to run this on?

#

No, v20 is fine. But in that case you can use es2022 target without issue, even es2024 is mostly supported in it

bitter hawk
#

Why is there both .js and .ts in your src folders? You should locate the folder you transpile too outside the src folder and you should put the relative paths for your ts files. tsc will take care of adjusting them accordingly

bitter hawk
#

Where’s the bot.ts that transpiles to that bot.js you have in test directory? It looks like you coded that in js directly?

bitter hawk
#

Then why do you have a bot.js that‘s in your test folder and not its Utils subfolder?

bitter hawk
#

No. You shouldn’t put any .js file manually anywhere. Make only .ts files. even for your main file, be it src/index.ts or src/bot.ts whatever you call your main file you run

#

And why is your test folder (which tbh would be better named as dist or build or whatever) now inside your src/Utils folder waitWhat

#

You write only ts in src folder. You run only js in dist folder

bitter hawk
#

Where do you have endsWith ts? In your command/event loader? You should have endsWith js there, because during runtime your files will all be js