[Schema Inaccuracy] GET /repos/{owner}/{repo}/issues/{issue_number}/timeline" events union is not discriminating
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- openapi, typescript
- Domain
- api
Research direction
Start with the OpenAPI schema for GET /repos/{owner}/{repo}/issues/{issue_number}/timeline and inspect how its event response union is defined. Check how the event field is represented across variants, then verify that event values discriminate the payload so timelineEvent.created_at is available for merged events.
Written by the indexing model from the issue text.
Description
What happened?
const timelinePages = octokit.paginate.iterator(
octokit.issues.listEventsForTimeline,
{ repo, owner, issue_number },
);
(async function () {
for await (const page of timelinePages) {
for (const timelineEvent of page.data) {
if (timelineEvent.event === "merged") timelineEvent.created_at;
}
}
})().catch((e) => console.log(e));
gives an error
Property 'created_at' does not exist on type '{ id: number; node_id: string; url: string; actor: { name?: string | null | undefined; email?: string | null | undefined; login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string | null; ... 14 more ...; user_view_type?: string | undefined; }; ... 5 more ...; label: { ...; }; } | ... 20 mo...'.
Property 'created_at' does not exist on type '{ event?: string | undefined; sha: string; node_id: string; url: string; author: { date: string; email: string; name: string; }; committer: { date: string; email: string; name: string; }; message: string; tree: { ...; }; parents: { ...; }[]; verification: { ...; }; html_url: string; }'. (ts 2339)
because TypeScript doesn't seem to have a way to discriminate the values in the union of event types.
It's basically impossible to inspect any of the event payload in a typed way due to this union being overlapping.
I think the fix would be to use the event field as a discriminator.
Versions
Octokit 22.0
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct
The told me to reopen this issue here: https://github.com/octokit/types.ts/issues/676#issuecomment-3135915038
- Dominant language
- No language data
- Stars
- 1.6k
- Forks
- 342
- Avg merge
- 3h 33m
- Merged PRs (30d)
- 51
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from github/rest-api-description
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
github/rest-api-description#7201 ·
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
github/rest-api-description#7163 ·
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
github/rest-api-description#7162 ·
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
github/rest-api-description#7135 ·
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
github/rest-api-description#7111 · 1 comment ·
All issues in github/rest-api-description
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
use-agent-os/agent-os#3312 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
needs-acceptance wg/data-plane-networking
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vllm-project/semantic-router#4024 · 1 comment ·
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
amponce/archive-movie-browser#165 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100