-
Notifications
You must be signed in to change notification settings - Fork 296
Open
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: octokit/types.ts#676 (comment)
Metadata
Metadata
Assignees
Labels
No labels