@@ -4,7 +4,7 @@ import type { GitifyNotification, GitifySubject, Link } from './types';
44
55// TODO: #828 Add explicit types for GitHub API response vs Gitify Notifications object
66
7- // Stronger typings for Reason string attribute
7+ // Stronger typings for string literal attributes
88export type Reason =
99 | 'approval_requested'
1010 | 'assign'
@@ -22,7 +22,6 @@ export type Reason =
2222 | 'subscribed'
2323 | 'team_mention' ;
2424
25- // Stronger typings for Subject Type string attribute
2625export type SubjectType =
2726 | 'CheckSuite'
2827 | 'Commit'
@@ -35,68 +34,82 @@ export type SubjectType =
3534 | 'RepositoryVulnerabilityAlert'
3635 | 'WorkflowRun' ;
3736
38- // Stronger typings for Reason User Type attribute
3937export type UserType =
4038 | 'Bot'
4139 | 'EnterpriseUserAccount'
4240 | 'Mannequin'
4341 | 'Organization'
4442 | 'User' ;
4543
46- export type Notification = GitHubNotification &
47- GitifyNotification & {
48- reason : Reason ;
49- subject : Subject ;
50- repository : Repository ;
51- } ;
52- export type Subject = GitHubSubject & {
44+ // Base types from Octokit
45+ export type NotificationThreadSubscription =
46+ components [ 'schemas' ] [ 'thread-subscription' ] ;
47+
48+ type BaseNotification = components [ 'schemas' ] [ 'thread' ] ;
49+ type BaseUser = components [ 'schemas' ] [ 'simple-user' ] ;
50+ type BaseRepository = components [ 'schemas' ] [ 'repository' ] ;
51+ type BaseCommit = components [ 'schemas' ] [ 'commit' ] ;
52+ type BaseCommitComment = components [ 'schemas' ] [ 'commit-comment' ] ;
53+ type BaseRelease = components [ 'schemas' ] [ 'release' ] ;
54+ type BaseSubject = components [ 'schemas' ] [ 'thread' ] [ 'subject' ] ;
55+
56+ // Strengthen user-related types with explicit property overrides
57+ type GitHubNotification = Omit <
58+ BaseNotification ,
59+ 'reason' | 'subject' | 'repository'
60+ > & {
61+ reason : Reason ;
62+ subject : Subject ;
63+ repository : Repository ;
64+ } ;
65+
66+ type GitHubSubject = Omit <
67+ BaseSubject ,
68+ 'url' | 'latest_comment_url' | 'type'
69+ > & {
5370 url : Link ;
5471 latest_comment_url : Link ;
5572 type : SubjectType ;
56- } & GitifySubject ;
73+ } ;
5774
58- export type User = components [ 'schemas' ] [ 'simple-user' ] & { type : UserType } ;
75+ // Exported strengthened types
76+ export type Notification = GitHubNotification & GitifyNotification ;
5977
60- export type GitHubNotification = components [ 'schemas' ] [ 'thread' ] ;
61- export type GitHubSubject = components [ 'schemas' ] [ 'thread' ] [ 'subject' ] ;
78+ export type Subject = GitHubSubject & GitifySubject ;
6279
63- export type Repository = components [ 'schemas' ] [ 'repository' ] & {
80+ export type Repository = Omit < BaseRepository , 'html_url' | 'owner' > & {
6481 html_url : Link ;
6582 owner : Owner ;
6683} ;
6784
68- export type Owner = NonNullable < BaseRepository [ 'owner' ] > & {
85+ export type User = Omit < BaseUser , 'type' > & { type : UserType } ;
86+
87+ export type Owner = Omit <
88+ NonNullable < BaseRepository [ 'owner' ] > ,
89+ 'type' | 'avatar_url'
90+ > & {
6991 type : UserType ;
7092 avatar_url : Link ;
7193} ;
72- type BaseRepository = components [ 'schemas' ] [ 'repository' ] ;
7394
95+ // Strengthen commit-related types
7496export type Commit = Omit < BaseCommit , 'author' > & {
75- author : BaseCommit [ 'author' ] extends null ? null : StrongCommitAuthor ;
76- } ;
77- type BaseCommit = components [ 'schemas' ] [ 'commit' ] ;
78- type StrongCommitAuthor = NonNullable < BaseCommit [ 'author' ] > & {
79- type : UserType ;
97+ author : BaseCommit [ 'author' ] extends null
98+ ? null
99+ : NonNullable < BaseCommit [ 'author' ] > & { type : UserType } ;
80100} ;
81101
82102export type CommitComment = Omit < BaseCommitComment , 'user' > & {
83- user : BaseCommitComment [ 'user' ] extends null ? null : StrongCommitCommentUser ;
84- } ;
85- type BaseCommitComment = components [ 'schemas' ] [ 'commit-comment' ] ;
86- type StrongCommitCommentUser = NonNullable < BaseCommitComment [ 'user' ] > & {
87- type : UserType ;
103+ user : BaseCommitComment [ 'user' ] extends null
104+ ? null
105+ : NonNullable < BaseCommitComment [ 'user' ] > & { type : UserType } ;
88106} ;
89107
90108export type Release = Omit < BaseRelease , 'author' > & {
91- author : BaseRelease [ 'author' ] extends null ? null : StrongReleaseAuthor ;
109+ author : BaseRelease [ 'author' ] extends null
110+ ? null
111+ : NonNullable < BaseRelease [ 'author' ] > & { type : UserType } ;
92112} ;
93- type BaseRelease = components [ 'schemas' ] [ 'release' ] ;
94- type StrongReleaseAuthor = NonNullable < BaseRelease [ 'author' ] > & {
95- type : UserType ;
96- } ;
97-
98- export type NotificationThreadSubscription =
99- components [ 'schemas' ] [ 'thread-subscription' ] ;
100113
101114export interface GitHubRESTError {
102115 message : string ;
0 commit comments