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
Conversation
This will give typescript the correct return type.
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.
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; |
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 think there is such a thing as repository.owner.name
? It's always owner.login
, even for organizations
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'm not sure, I just took it from here:
Line 76 in 718025d
owner: repo.owner.login || repo.owner.name, |
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.
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
🎉 This PR is included in version 12.1.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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?