Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish converting to TypeScript #611

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

webwarrior-ws
Copy link
Contributor

Convert all remaining JavaScript code to TypeScript.

Convert bot/modules/community module to TypeScript.
Convert bot/modules/disputemodule to TypeScript.
Convert bot/modules/eventsmodule to TypeScript.
Convert bot/modules/language to TypeScript.
Convert bot/modules/nostr to TypeScript.
Specified "lib" property in tsconfig.json because otherwise
TypeScript compiler complains about usage of `Promise.any`
in bot/modules/nostr/index.ts:
```
Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the lib compiler option to 'es2021' or later.
```
Convert bot/modules/user to TypeScript.
Convert bot/middleware to TypeScript.
Convert bot module (except bot/modules/orders) to TypeScript.

Had to make several changes to IOrder model to allow some
fields to have null or undefined value, as there is code that
assigns these values.

Also changed signature of several functions in bot/messages.ts
so that `bot` argument now has `MainContext` type instead of
`Telegraf<MainContext>`, because that's what gets passed by
code calling those functions.
Introduced HasTelegram type for use in functions that
have `bot` argument, which can be either `Context` or
`Telegraf<Context>`, but only `telegram` property is used.
Convert bot/modules/orders module to TypeScript.
Converted requires to imports where applicable and fixed
type errors resulting from it.
Convert ln module to TypeScript.
Add type packages needed for Typescript code to package.json.
Setup eslint so that it checks .ts files instead of .js.
Fix "Import in body of module; reorder to top  import/first"
eslint errors.
From Promise<void> to Promise<undefined>, to get rid of the
following error:
```
tests/bot/validation.spec.ts(376,19): error TS2339: Property 'tg_id' does not exist on type 'void | (UserDocument & { _id: ObjectId; })'.
  Property 'tg_id' does not exist on type 'void'.
```
Silenced remaining eslint errors as what they refer to is
intended behavior.
By adding guards for values that can be null/undefined.
Because all code is now converted to TS.
@grunch
Copy link
Member

grunch commented Dec 19, 2024

Hi @webwarrior-ws this is a great contribution, but please remember to split it on smaller PR for a easier review 😃

@webwarrior-ws
Copy link
Contributor Author

Converted first 4 commits into separate PRs:

#623
#624
#625
#626

@webwarrior-ws
Copy link
Contributor Author

One more PR:
#627

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants