types.ts
types.ts copied to clipboard
[FEAT]: Discriminated unions for (issue timeline) events
Describe the need
I have type safety issues with listEventsForTimeline operation where I have to use type casting with the as keyword in typescript based on switching the event type. Using the octokit/rest.js client, the code looks like this:
const response = await octokit.issues.listEventsForTimeline({
owner: "OWNER",
repo: "REPO",
issue_number: PULL_NUMBER,
});
response.data.forEach( (item) => {
if (item.event === "reviewed") {
// here is the issue: need to type cast the item in order to get the underlying type.
const reviewedEvent = item as components["schemas"]["timeline-reviewed-event"];
}
});
It would be useful if discriminated unions were used instead to provide type switching by definition. I put the issue timeline in the title in parentheses as I'm not sure if there are other component schemas that can benefit from this approach.
I assume the component schemas are generated from the API documentation, so I'm not sure if this is possible.
....On an unrelated note, can anyone tell me where I can report bugs for the GitHub API and/or where I can request documentation for undocumented APIs.
SDK Version
No response
API Version
No response
Relevant log output
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀
....On an unrelated note, can anyone tell me where I can report bugs for the GitHub API and/or where I can request documentation for undocumented APIs.
In the past, we've pointed people here to make requests for API features and bugs.