@@ -32,27 +32,27 @@ export async function setAuthToken(authToken: string | null): Promise<void> {
3232}
3333setAuthToken ( settings . value . authToken ) ;
3434
35- export function fetch ( url : Route , options : RequestParameters = { } ) : Promise < any > {
35+ export function fetch < T > ( url : Route , options : RequestParameters = { } ) : Promise < T > {
3636 const NO_CACHE_LIMIT = 4000 ;
3737 const bypassCache : boolean = Number ( rateLimit . value ) > NO_CACHE_LIMIT ;
3838 return octokit . request ( url , {
3939 ...options ,
4040 headers : bypassCache ? { "If-None-Match" : "" } : undefined
41- } ) ;
41+ } ) as Promise < T > ;
4242}
4343
4444export async function fetchRateLimit ( ) {
45- const { data } = await fetch ( "GET /rate_limit" ) as RateLimitResponse ;
45+ const { data } = await fetch < RateLimitResponse > ( "GET /rate_limit" ) ;
4646 rateLimit . value = data . rate . remaining . toString ( ) ?? "-" ;
4747}
4848
4949export async function fetchRepo ( fullName : Repository [ "full_name" ] ) {
50- const { data } = await fetch ( `GET /repos/${ fullName } ` ) as RepoResponse ;
50+ const { data } = await fetch < RepoResponse > ( `GET /repos/${ fullName } ` ) ;
5151 return data ;
5252}
5353
5454async function fetchRepositoryContents ( fullName : Repository [ "full_name" ] ) {
55- const { data } = await fetch ( `GET /repos/${ fullName } /contents` ) as RepoContentsResponse ;
55+ const { data } = await fetch < RepoContentsResponse > ( `GET /repos/${ fullName } /contents` ) ;
5656 return data ;
5757}
5858
@@ -67,7 +67,7 @@ export const fetchRepositoryFiles = useMemoize(async (fullName: Repository["full
6767} ) ;
6868
6969async function fetchRepositoryFile ( fullName : Repository [ "full_name" ] , fileName : string ) {
70- const { data } = await fetch ( `GET /repos/${ fullName } /contents/${ fileName } ` ) as RepoContentsResponse ;
70+ const { data } = await fetch < RepoContentsResponse > ( `GET /repos/${ fullName } /contents/${ fileName } ` ) ;
7171 if ( "content" in data ) return atob ( data . content ) ;
7272 throw new Error ( "Invalid file" ) ;
7373}
@@ -87,7 +87,7 @@ export async function fetchRepositoryPackages(fullName: Repository["full_name"])
8787
8888export async function fetchRepositoryWorkflows ( fullName : Repository [ "full_name" ] ) {
8989 try {
90- const { data } = await fetch ( `GET /repos/${ fullName } /actions/workflows` ) as WorkflowsResponse ;
90+ const { data } = await fetch < WorkflowsResponse > ( `GET /repos/${ fullName } /actions/workflows` ) ;
9191 return data ;
9292 } catch ( error : unknown ) {
9393 if ( isRequestError ( error ) && error . status !== StatusCodes . NOT_FOUND ) console . error ( error ) ;
@@ -96,19 +96,19 @@ export async function fetchRepositoryWorkflows(fullName: Repository["full_name"]
9696}
9797
9898export async function fetchRepositoryEvents ( fullName : Repository [ "full_name" ] , page = 1 ) {
99- const { data } = await fetch ( `GET /repos/${ fullName } /events` , { per_page : 100 , page } ) as RepoEventsResponse ;
99+ const { data } = await fetch < RepoEventsResponse > ( `GET /repos/${ fullName } /events` , { per_page : 100 , page } ) ;
100100 if ( ! Array . isArray ( data ) ) throw new Error ( `Error fetching ${ fullName } repo events` , data ) ;
101101 return { data } ;
102102}
103103
104104export async function fetchCurrentUser ( ) {
105105 if ( ! settings . value . authToken ) return console . warn ( "empty authToken" ) ;
106- const { data } = await fetch ( "GET /user" ) as UserResponse ;
106+ const { data } = await fetch < UserResponse > ( "GET /user" ) ;
107107 return data ;
108108}
109109
110110export async function fetchCurrentUserRepos ( ) {
111111 if ( ! settings . value . authToken ) return console . warn ( "empty authToken" ) ;
112- const { data } = await fetch ( "GET /user/repos" , { affiliation : "owner" } ) as UserReposResponse ;
112+ const { data } = await fetch < UserReposResponse > ( "GET /user/repos" , { affiliation : "owner" } ) ;
113113 return data ;
114114}
0 commit comments