-
Notifications
You must be signed in to change notification settings - Fork 951
Types and examples for scenes and wizards #1194
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see anything obviously very wrong, but I understand pretty much nothing here...
Then check out what is going on in #1195 … no but seriously, do you think that I should write more comments? |
I don't know, better ask someone familiar with Scenes/Stages/Wizards |
Who would that be? I also had no idea about these things before I started working on this PR, so I'd appreciate it if someone with more experience than me could have a look. |
@dotcypress |
79fa722
to
a57664e
Compare
@IMalyugin @wwwat @foodornt you all seem to be interested in having TypeScript types for Stages/Scenes. The types are fixed now. However, I have never used that feature of
This would be very helpful. We cannot merge this without other people's approval :) Regarding the third point: I will write (UPDATE: done) some examples about how to that. This is necessary anyway, but please don't hesitate to validate the first two things already! |
Some type variables are redundant. It has to be possible to infer certain variables across This needs to be figured out before a merge. |
I added a lot of example bots. They illustrate every possible way to use the type variables. It's mostly redundant stuff, so it should be enough to check out the most basic one and the most advanced one for reviewing this PR. There is a lot of nesting of the same objects for scenes and sessions and sessions in scenes and so on. This makes it very convenient to use, so I don't think we should change it, but it also makes the types a bit annoying internally. They are pretty much fine on the surface, though. |
I figured out #1194 (comment). The problem is that As a consequence, whenever the scene session under It is difficult to explain to new users why type inference works correctly for scenes but not for wizards in this place. Hence, it makes sense to simply advise to consequently specify both type variables for |
Please review and test #1224, after it's merged you can merge |
I'd still be happy to get review from someone more experienced with the stuff before I approve. |
@wojpawlik For reviewing this, it helps a lot to install
to inspect that the scenes actually do their job. #705 also helps a lot, that's what I read before getting into it. The types are easy to check by verifying that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be great if you sorted these out:
/home/runner/work/telegraf/telegraf/src/scenes/context.ts
Warning: 101:10 warning Unexpected nullable object value in conditional. An explicit null check is required @typescript-eslint/strict-boolean-expressions
Warning: 120:10 warning Unexpected nullable object value in conditional. An explicit null check is required @typescript-eslint/strict-boolean-expressions
/home/runner/work/telegraf/telegraf/src/stage.ts
Warning: 27:12 warning Unexpected string value in conditional. An explicit empty string check is required @typescript-eslint/strict-boolean-expressions
Other than that, I don't see anything wrong here, but to be honest I understand almost nothing, so I just trust TypeScript (and you).
If no one else shows up and pops a question until the end of tomorrow, I'll merge. I have tested example bots for both scenes and wizards thoroughly and they worked without problems. Writing the other example bots made me confident that the types are correct. Even if we missed something here, the existing types will be an order of magnitude better than the current state, so the rest is fixing bugs (and I can do that). |
Description
The types of Stages, Scenes, and Wizards were mostly wrong. The examples did not typecheck.
This PR applies consistent types to this part of the library. The example bots are migrated to TS, they build now with minimal changes.
While the types should be correct everywhere now, this comes with the downside of complexity. Scenes rely on the session. As a result, everything is bloated up to having two type variables: one for the session data and one for the context object, as both types can be adjusted. This trickles down far.
Note that the type variables follow the standard convention of single character names rather than the special
telegraf
version of prepending aT
. We can change this back if desired, I simply found it even less readable than the current version to make all names longer.Fixes #1172
Fixes #1165
Fixes #894
Helps with
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Checklist: