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

fix(intellisense): intellisense for array arg in on #141

Merged
merged 13 commits into from
May 20, 2020

Conversation

ankeetmaini
Copy link
Contributor

Fix #140

@oscard0m oscard0m added Type: Bug Something isn't working as documented, or is being fixed typescript Relevant to TypeScript users only labels May 16, 2020
@oscard0m
Copy link
Member

oscard0m commented May 16, 2020

Hi @ankeetmaini ! Thanks for contributing to this project. Intellisense is awesome. To make it work 100% for octokit users is a game changer in developer's experience. If we get this fixed will be awesome :)

💬 Feedback:

✅ Tested copy-pasting the index.d.ts in a dummy project and now it shows the events 🎉 :

Before

image

After

image


❓ With this change I see we lose support for use the same eventHandler for different event types -> i.e.:

this works because these are events from the same "event suite"

webhooks.on(["check_run", "check_run.completed"], ({ name }) => {
    console.log(name, "event received");
})

this does not work because are events from different "event suites"

webhooks.on(["check_run", "label.edited"], ({ name }) => {
    console.log(name, "event received");
})

image

I think we should keep compatibility for this use case but let's see what @gr2m thinks about it.


Extra ball: On this pull request it is planned to cover your use case and split the type declaration in several files to have a better structure. Maybe you are interested on following it up or even participate on it.

@oscard0m oscard0m requested a review from gr2m May 16, 2020 11:39
@oscard0m
Copy link
Member

Also, I would say to wait to land these fixes which will give back stability to index.d.ts. Do you think it would have sense @ankeetmaini

@ankeetmaini
Copy link
Contributor Author

Also, I would say to wait to land these fixes which will give back stability to index.d.ts. Do you think it would have sense @ankeetmaini

Sure, it can wait till we get these two merged in!

@ankeetmaini
Copy link
Contributor Author

I can try and see if we can keep the same handler usecase. Also if #113 is slated to go in soon, I can close this and help out. :)

@oscard0m
Copy link
Member

I can try and see if we can keep the same handler usecase. Also if #113 is slated to go in soon, I can close this and help out. :)

🆒 , if you need help with it let us know :)

@ankeetmaini
Copy link
Contributor Author

@dominguezcelada I've removed all the hardcoded overloads and used conditional types to store the mapping of type -> Payload. I also added the same signature for removeListener which now adds intellisense to it.

Intellisense works great for array params (likewise for on)

Screenshot 2020-05-17 at 4 12 56 PM

it calculates the payload types

Screenshot 2020-05-17 at 4 14 51 PM

@gr2m
Copy link
Contributor

gr2m commented May 18, 2020

I think we should keep compatibility for this use case but let's see what @gr2m thinks about it.

I agree but this is better than what we have now.

@dominguezcelada PR looks good to me if you think it's good. We can iterate on details

@oscard0m
Copy link
Member

@ankeetmaini nice job doing the type generation more generic with conditional types.

PR's fixing index.d.ts are on master already.

An idea that came in my mind is to extend typescript-validate.ts test adding the following cases to double check your changes are keeping retrocompatibility:

webhooks.on("check_run.completed", () => {})
webhooks.on(["check_run.comppleted", "check_run.created"], () => {})
webhooks.on(["check_run.comppleted", "commit_comment"], () => {})

And for
webhooks.removeListener()

If you need help with it, let me know :)

@ankeetmaini
Copy link
Contributor Author

@dominguezcelada I've added the changes for validating type fixes. Let me know if something more needs to be done!

@oscard0m
Copy link
Member

@dominguezcelada I've added the changes for validating type fixes. Let me know if something more needs to be done!

Amazing Job @ankeetmaini. Tried it in a dummy repo and works good to me :)

@oscard0m oscard0m changed the title fix: intellisense for array arg in on fix(intellisesne): intellisense for array arg in on May 20, 2020
@oscard0m oscard0m merged commit 6311878 into octokit:master May 20, 2020
@github-actions
Copy link
Contributor

🎉 This PR is included in version 7.6.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ankeetmaini ankeetmaini deleted the fix-array-types branch May 21, 2020 02:34
@gr2m gr2m changed the title fix(intellisesne): intellisense for array arg in on fix(intellisense): intellisense for array arg in on Jan 17, 2021
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 this pull request may close these issues.

No intellisense when on has an array for event names
3 participants