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: added definite type so that caller does not get warnings #1622

Merged
merged 3 commits into from Nov 29, 2021

Conversation

kammerjaeger
Copy link
Contributor

@kammerjaeger kammerjaeger commented Nov 29, 2021

This will give typescript the correct return type.

My ts compiler complains about the any type, this should fix it.
Only question would be if the context type does not support some of the properties the correct type would be undefined.
This would mask the error.
The first commit is the easy solution, the second uses conditional types to detect that problem.

Let me know what you think.
Should I add export to the types?

@kammerjaeger kammerjaeger requested a review from a team as a code owner November 29, 2021 19:21
Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

This is great thank you! Just one comment

src/context.ts Outdated
/** Repo owner type, either string or never depending on the context */
type RepoOwnerType<T extends WebhookEvents> =
WebhookEvent<T>["payload"] extends { repository: { owner: { login: string } } } ? string : never |
WebhookEvent<T>["payload"] extends { repository: { owner: { name: string } } } ? string : never;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there is such a thing as repository.owner.name? It's always owner.login, even for organizations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, I just took it from here:

owner: repo.owner.login || repo.owner.name,

Copy link
Contributor

Choose a reason for hiding this comment

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

got it, it's out of scope of this PR then. .name does exist, but it's human name of the owner, such as "Gregor Martynus" for @gr2m. This code is not correct. If you like feel free to send a PR to fix that and remove the || repo.owner.name part

@gr2m gr2m merged commit 638a3b2 into probot:master Nov 29, 2021
@github-actions
Copy link

🎉 This PR is included in version 12.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants