JackDotJS / vector-bot

A Discord bot for advanced moderation and server management.
https://discord.gg/s5nQBxFPp2
MIT License
15 stars 3 forks source link

WIP: TypeScript! #4

Closed bdotsamir closed 2 years ago

bdotsamir commented 2 years ago

Convert the bot to typescript. This will be an ongoing project for myself.

bdotsamir commented 2 years ago

This isn't a hard fork of the bot; as commits land in the dev branch i'll merge them into here as well.

bdotsamir commented 2 years ago

So far the bot cannot start because TSc cannot transpile. There are a little over 200 (strict mode) issues that need to be solved first before it'll even think about it.

bdotsamir commented 2 years ago

it keeps saying that the merges are unverified, trust me, they're me.

bdotsamir commented 2 years ago

jack, just so we're on the same page, is this actually something you'd like to do with vector? turn it into a typescript project? i just submitted this PR for funsies, but if you're willing to, i'd love to continue working on this

JackDotJS commented 2 years ago

im not entirely sure yet

the main thing im worried about is dependencies, since most of them use regular js instead of ts

i wanna know, how does ts interact with js? and vice versa

bdotsamir commented 2 years ago

typescript is a superset of javascript. that is to say, any valid js code is valid ts code. the only difference is that ts is type-safe (by opt-in, which i have), and somewhat more object oriented.

the typescript "compiler" just takes any ts code, checks for the rules of ts, and transpiles the code down to javascript, which is then run by nodejs in this case. as far as libraries go, follow the first paragraph. any js code is valid ts code. they'll sometimes include "types," which means either: a) the lib itself is written in ts, which is fine, because it's ts on ts code. or, b) there's a special file the devs include (you might see it sometimes, the index.d.ts file) to define the types of the inputs and outputs of the methods exported by the lib. if neither of these options are available, there are crowdsourced types available through the DefinitelyTyped repo, which you can install to your dev dependencies through yarn add --dev @types/package.

bdotsamir commented 2 years ago

And for what it's worth, there are only very rare cases when a package doesn't have types at all. For those, you can manually define them yourself, or submit a pr to the DT repo (like i did here for jaro-winkler). It takes about a week for those PRs to be accepted.

bdotsamir commented 2 years ago

update: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56607 was merged. types for jaro-winkler are now live 🎉

bdotsamir commented 2 years ago

In case you were still interested in this, there's a video i just saw that sums up TS pretty well. https://youtu.be/EUlM3wx546o

bdotsamir commented 2 years ago

image

bdotsamir commented 2 years ago

first commit pushed from my ipad hell yeah gamers we code on the roll 😎

JackDotJS commented 2 years ago

iVector

bdotsamir commented 2 years ago

Checking in on this by the way, is this still a project you'd care to see more progress on?

JackDotJS commented 2 years ago

what is pnpm?

JackDotJS commented 2 years ago

Checking in on this by the way, is this still a project you'd care to see more progress on?

(also for future reference: i accidentally answered this over discord before i even saw this comment lmao)

image image

bdotsamir commented 2 years ago

what is pnpm?

pnpm is an alternative to npm that hosts all of your node_modules in a single folder somewhere. Each time a new dependency is added to a project, pnpm checks that folder to see whether or not the module exists, and links to it. If it doesn't exist, it downloads it into the main folder and links to it. This reduces the amount of storage space that gets utilized by every node project you work on.

JackDotJS commented 2 years ago

pnpm is an alternative to npm that hosts all of your node_modules in a single folder somewhere. Each time a new dependency is added to a project, pnpm checks that folder to see whether or not the module exists, and links to it. If it doesn't exist, it downloads it into the main folder and links to it. This reduces the amount of storage space that gets utilized by every node project you work on.

....

WHY IS THIS NOT A FEATURE OF REGULAR NPM

bdotsamir commented 2 years ago

Unassigning myself as this is something Jack and I are now working on jointly

JackDotJS commented 2 years ago

since vector is going full-time TS, would it be appropriate (and possible) to merge this now?

bdotsamir commented 2 years ago

not yet. in its current state, the codebase doesn't compile. still working out some kinks. i'll unmark as WIP when i'm finished and we can continue from there.

JackDotJS commented 2 years ago

what seems to be causing it?

bdotsamir commented 2 years ago

not at my pc at the moment. will get back to you later, although you're free to clone my fork and see for yourself in the mean time

bdotsamir commented 2 years ago

currently the API section (namely api.ts) is seemingly unable to be converted to TS due to the fact that the Express type that gets assigned to the app variable is not publicly accessible. We're now faced with an interesting catch-22 situation; do we complete #9 in order to complete this PR or do we complete this pr in order to complete #9?

bdotsamir commented 2 years ago

We could also create a branch of this branch, work on replacing express, and merge that branch into this PR. That gets a bit into the weeds though, and we have to be super sure we're committing to the right branch.