-
Notifications
You must be signed in to change notification settings - Fork 954
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
Type Parameter Issues for Context
#1968
Type Parameter Issues for Context
#1968
Comments
That's the only solution I have for you right now, sorry. The type issues don't happen with the payload nor Octokit, and I don't think it's the logger as that is the same method regardless of the event. I'm thinking it's probably the convenience methods that are causing this, as they are heavily tied to the input event names when instantiating the Originally posted by @wolfy1339 in #1966 (reply in thread)
|
I suffered from this issue for a while. I was able to work around it by separating the So instead of: // not attached to a webhook event
async function checkReadyToMerge(context: Context<'pull_request.labeled' | 'pull_request_review.submitted'>): Promise<boolean> {
// do something
}; try this: // not attached to a webhook event
async function checkReadyToMerge(context: Context, payload: Context<'pull_request.labeled' | 'pull_request_review.submitted'>["payload"]): Promise<boolean> {
// do something
}; Hope this helps. |
Fixes #1968 > error TS2590: Expression produces a union type that is too complex to represent.
🎉 This issue has been resolved in version 13.3.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Discussed in #1966
Originally posted by tmercswims February 5, 2024
This discussion is essentially the same problem as #1680, so I'll try to summarize and simplify as much as I can. The solutions given on that issue are not working for me, and rather than resurrect a closed issue I figured I'd start fresh.
The bot I'm making is in TypeScript. As such, I want/need to use type parameters on
Context
in order for it to have the properties that it should have on itspayload
. Typically that looks something like this:The problem I'm facing is whenever I try to do anything else with the
Context
which implies some difference in the types, even if that difference "should" be allowed. Consider this situation:In this case, I care about two different webhook events, which aren't the same but are similar enough that I can do the same processing to both of them. I've set the types up to support that, as you can see.
However, this does not work. TypeScript gets mad on whichever call of
checkReadyToMerge()
it encounters first during complication, with the following error:If I change things so that type parameters of everything here match exactly, for example make them all
Context<'pull_request.labeled'>
, then that error does not occur. But that isn't what I want, I wantonPullRequestReviewed
to take a context of typeContext<'pull_request_review.submitted'>
. This happens if there is a mismatch in the type parameter of any twoContext
types, assuming that one calls the other or something like that. It even happens if one of them's type parameter is omitted entirely, or is set toany
.I have also tried unioning on multiple
Context
s, each with a single, different type parameter, (Context<'pull_request_review.submitted'> | Context<'pull_request.labeled'>
instead) but the same error occurs when compiling.The same problem also happens if I'm using sub-types of a webhook, like one handler for
pull_request.opened
and another forpull_request.labeled
which both call a helper function which is set up to takeContext<'pull_request'>
. I'd expect either ofpull_request.opened
andpull_request.labeled
to satisfy the type requirement for justpull_request
, and maybe it would, but TypeScript complains with the same complexity error before I can know.I can always get around these issues by strategically casting things to
any
, but I'd really rather not do that if I can at all help it.I'm looking for any advice on what to do here. Thank you!
Versions of relevant things:
The text was updated successfully, but these errors were encountered: