Skip to content

Conversation

trgwii
Copy link

@trgwii trgwii commented Jul 13, 2020

Description

Adds improved typings to src/telegraf.ts

  • Documentation (typos, code examples or any documentation update)
  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

All tests pass

Test Configuration:

  • Node.js Version: v14.4.0
  • Operating System: Windows 10

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Comment on lines +10 to +11
import http from 'http'
import https from 'https'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of doing this? The drawback is obvious -- it'll need to be changed back if esModuleInterop is disabled.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to make it as tidy as possible for now, esModuleInterop changes later are easy to fix

telegram: {},
retryAfter: 1,
handlerTimeout: 0,
channelMode: false,
contextType: Context,
}

const noop = () => {}
const noop: () => void = () => undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just more verbose way of doing the same thing, isn't it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this fixes a type error further down, where another function expects a void callback, and not an undefined callback

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How? () => {} is already a void callback.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, NOW it is for me too, previously this wasn't a void callback but the type turned into () => undefined.. uhh

// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
debug(`Launching @${botInfo.username}`)
debug(
`Launching ${botInfo.username == null ? 'bot' : '@' + botInfo.username}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code, bots always have a username as far as I'm aware. The real solution here is to tighten the type returned by getMe and stored in botInfo to something like

interface BotUser {
  id: number
  is_bot: true
  first_name: string
  username: string
  can_join_groups: boolean
  can_read_all_group_messages: boolean
  supports_inline_queries: boolean
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we'll fix that later, I'd enjoy seeing some extending here, since BotUser would just be an extension of User in this case

Comment on lines +100 to +102
console.error(
('stack' in err ? err.stack : err.toString()).replace(/^/gm, ' ')
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing wrong with this, but it also doesn't seem to fix anything.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It checks that err.stack is a property on err, instead of checking if it's nullish

@wojpawlik wojpawlik mentioned this pull request Jul 13, 2020
26 tasks
trgwii and others added 3 commits July 27, 2020 07:59
@trgwii trgwii requested a review from wojpawlik July 27, 2020 06:07
@KnorpelSenf
Copy link
Collaborator

Any ETA for this? What is the current state?

I'm waiting for this because it is blocking #1074.

@wojpawlik
Copy link
Member

I don't think it's blocking, as long as you don't touch src/telegraf.ts. Still, feel free to make any changes, I'll close this if serious conflicts arise, as @trgwii seems to be ignoring some of my feedback.

@trgwii
Copy link
Author

trgwii commented Aug 9, 2020

@wojpawlik would it be possible for me to give you write access to my fork? I'm not very interested in arguing about these tiny things I really don't care about, but I'm fìne with letting you have final say on all of these as long as my code gets merged. I enjoy making larger contributions than these changes

@KnorpelSenf
Copy link
Collaborator

Save your time you two. I'll just pull your work into my fork and then continue the migration journey from there. I'll most likely need to touch most lines of the codebase anyway. After all, half of it is still JS. I applied a reasonably tight TS config for a project of this size and I'm at nearly 300 compilation errors now. It's not just gonna take a week before this is done. I'll submit a separate PR once I have a first proper step to share.

@KnorpelSenf KnorpelSenf mentioned this pull request Aug 18, 2020
7 tasks
@KnorpelSenf
Copy link
Collaborator

@trgwii please check out if something slipped through on my side or if you're missing something else in my PR, I'll happily add it

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.

3 participants