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

Passing down event name into TransformMethod to allow for the right payload types to be used #490

Closed
wolfy1339 opened this issue Mar 10, 2021 · 4 comments · Fixed by #494
Labels
Type: Bug Something isn't working as documented, or is being fixed typescript Relevant to TypeScript users only

Comments

@wolfy1339
Copy link
Member

I'm trying to fix the issue octokit/app.js#212, and I've hit a wall with types with the transform method.

How do I pass down the TName type parameter from the HandlerFunction type to TransformMethod?
The end result wanted is to keep all the same type inference as not having the transform method, and just apply the modifications from that function.

In this case, we would like the return type to be EmiterWebhookEvent<EventName extends EmitterWebhookEventName> & { octokit: Octokit }

@wolfy1339 wolfy1339 added typescript Relevant to TypeScript users only Type: Support Any questions, information, or general needs around the SDK or GitHub APIs labels Mar 10, 2021
@oscard0m
Copy link
Member

oscard0m commented Mar 12, 2021

I'm trying to fix the issue octokit/app.js#212, and I've hit a wall with types with the transform method.

How do I pass down the TName type parameter from the HandlerFunction type to TransformMethod?
The end result wanted is to keep all the same type inference as not having the transform method, and just apply the modifications from that function.

Hey @wolfy1339 I'm quite lost at this level of complexity in typing but I would like to help. I tried to play a bit myself and no luck but because I'm lacking expertise with generics and type inference at this level of complexity.

Do you think it could be useful to draft a simple example of our problem in TypeScript playground?


Tagging @G-Rath for a new TS battle ⚔️

@wolfy1339
Copy link
Member Author

wolfy1339 commented Mar 12, 2021

You can see the discussion on what the issue is: octokit/app.js#213 (comment)

Basically the first step to fixing this is to only allow the transform function to amend the event object

@wolfy1339
Copy link
Member Author

I am really not sure how to replicate what we have into the TS playground for a simpler example of the problem.
The types are spread across a couple packages and there's loads of generics to account for

@wolfy1339
Copy link
Member Author

This has turned into a bug. I confirmed that this is broken on master. Since we can't currently pass down the event name, it returns a combination of all the different event payloads

@wolfy1339 wolfy1339 added Type: Bug Something isn't working as documented, or is being fixed and removed Type: Support Any questions, information, or general needs around the SDK or GitHub APIs labels Mar 14, 2021
@wolfy1339 wolfy1339 linked a pull request Mar 14, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented, or is being fixed typescript Relevant to TypeScript users only
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants