From 281ed419a87fb4030ea1bb1e8d93c3ef3ab79de2 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Thu, 30 Jun 2022 11:34:23 -0700 Subject: [PATCH] Chore: add generics to backendSrv (#51606) --- .betterer.results | 46 ++++++++++--------- .../src/services/backendSrv.ts | 12 ++--- public/app/core/services/backend_srv.ts | 8 ++-- .../features/plugins/admin/state/reducer.ts | 3 +- public/app/features/search/service/sql.ts | 4 +- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/.betterer.results b/.betterer.results index d6181e09281..642e8bcaffa 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1231,24 +1231,24 @@ exports[`better eslint`] = { [88, 23, 34, "Do not use any type assertions.", "916459105"], [88, 54, 3, "Unexpected any. Specify a different type.", "193409811"] ], - "packages/grafana-runtime/src/services/backendSrv.ts:793786410": [ + "packages/grafana-runtime/src/services/backendSrv.ts:3777417514": [ [23, 27, 3, "Unexpected any. Specify a different type.", "193409811"], [56, 9, 3, "Unexpected any. Specify a different type.", "193409811"], [61, 26, 3, "Unexpected any. Specify a different type.", "193409811"], [88, 35, 3, "Unexpected any. Specify a different type.", "193409811"], [108, 19, 3, "Unexpected any. Specify a different type.", "193409811"], [116, 32, 3, "Unexpected any. Specify a different type.", "193409811"], - [145, 28, 3, "Unexpected any. Specify a different type.", "193409811"], - [145, 62, 3, "Unexpected any. Specify a different type.", "193409811"], - [146, 29, 3, "Unexpected any. Specify a different type.", "193409811"], - [146, 43, 3, "Unexpected any. Specify a different type.", "193409811"], - [147, 27, 3, "Unexpected any. Specify a different type.", "193409811"], - [147, 41, 3, "Unexpected any. Specify a different type.", "193409811"], - [148, 28, 3, "Unexpected any. Specify a different type.", "193409811"], - [148, 42, 3, "Unexpected any. Specify a different type.", "193409811"], - [149, 26, 3, "Unexpected any. Specify a different type.", "193409811"], - [149, 40, 3, "Unexpected any. Specify a different type.", "193409811"], - [155, 47, 3, "Unexpected any. Specify a different type.", "193409811"], + [145, 10, 3, "Unexpected any. Specify a different type.", "193409811"], + [145, 37, 3, "Unexpected any. Specify a different type.", "193409811"], + [146, 13, 3, "Unexpected any. Specify a different type.", "193409811"], + [146, 38, 3, "Unexpected any. Specify a different type.", "193409811"], + [147, 11, 3, "Unexpected any. Specify a different type.", "193409811"], + [147, 36, 3, "Unexpected any. Specify a different type.", "193409811"], + [148, 12, 3, "Unexpected any. Specify a different type.", "193409811"], + [148, 37, 3, "Unexpected any. Specify a different type.", "193409811"], + [149, 10, 3, "Unexpected any. Specify a different type.", "193409811"], + [149, 35, 3, "Unexpected any. Specify a different type.", "193409811"], + [155, 14, 3, "Unexpected any. Specify a different type.", "193409811"], [165, 24, 3, "Unexpected any. Specify a different type.", "193409811"] ], "packages/grafana-runtime/src/services/live.ts:3749886101": [ @@ -3617,7 +3617,7 @@ exports[`better eslint`] = { [0, 34, 3, "Unexpected any. Specify a different type.", "193409811"], [0, 39, 3, "Unexpected any. Specify a different type.", "193409811"] ], - "public/app/core/services/backend_srv.ts:2084076322": [ + "public/app/core/services/backend_srv.ts:1201556162": [ [83, 20, 3, "Unexpected any. Specify a different type.", "193409811"], [153, 63, 3, "Unexpected any. Specify a different type.", "193409811"], [231, 40, 3, "Unexpected any. Specify a different type.", "193409811"], @@ -3627,10 +3627,14 @@ exports[`better eslint`] = { [392, 49, 3, "Unexpected any. Specify a different type.", "193409811"], [396, 16, 3, "Unexpected any. Specify a different type.", "193409811"], [396, 43, 3, "Unexpected any. Specify a different type.", "193409811"], - [400, 35, 3, "Unexpected any. Specify a different type.", "193409811"], - [404, 33, 3, "Unexpected any. Specify a different type.", "193409811"], - [408, 33, 3, "Unexpected any. Specify a different type.", "193409811"], - [412, 31, 3, "Unexpected any. Specify a different type.", "193409811"], + [400, 19, 3, "Unexpected any. Specify a different type.", "193409811"], + [400, 44, 3, "Unexpected any. Specify a different type.", "193409811"], + [404, 17, 3, "Unexpected any. Specify a different type.", "193409811"], + [404, 42, 3, "Unexpected any. Specify a different type.", "193409811"], + [408, 18, 3, "Unexpected any. Specify a different type.", "193409811"], + [408, 42, 3, "Unexpected any. Specify a different type.", "193409811"], + [412, 16, 3, "Unexpected any. Specify a different type.", "193409811"], + [412, 40, 3, "Unexpected any. Specify a different type.", "193409811"], [416, 31, 3, "Unexpected any. Specify a different type.", "193409811"], [428, 16, 3, "Unexpected any. Specify a different type.", "193409811"] ], @@ -6422,7 +6426,7 @@ exports[`better eslint`] = { [93, 11, 110, "Do not use any type assertions.", "1968165501"], [108, 16, 33, "Do not use any type assertions.", "3811107685"] ], - "public/app/features/plugins/admin/state/reducer.ts:4117436501": [ + "public/app/features/plugins/admin/state/reducer.ts:3395541504": [ [26, 16, 534, "Do not use any type assertions.", "3555458827"] ], "public/app/features/plugins/admin/state/selectors.ts:345773501": [ @@ -6790,10 +6794,8 @@ exports[`better eslint`] = { [161, 24, 46, "Do not use any type assertions.", "1967560255"], [167, 22, 38, "Do not use any type assertions.", "1477056001"] ], - "public/app/features/search/service/sql.ts:4013142735": [ - [91, 36, 3, "Unexpected any. Specify a different type.", "193409811"], - [99, 18, 61, "Do not use any type assertions.", "2014388220"], - [104, 16, 68, "Do not use any type assertions.", "257067967"] + "public/app/features/search/service/sql.ts:3331148655": [ + [91, 36, 3, "Unexpected any. Specify a different type.", "193409811"] ], "public/app/features/search/types.ts:762810555": [ [56, 12, 3, "Unexpected any. Specify a different type.", "193409811"] diff --git a/packages/grafana-runtime/src/services/backendSrv.ts b/packages/grafana-runtime/src/services/backendSrv.ts index b5bdd774a2f..27e743447dc 100644 --- a/packages/grafana-runtime/src/services/backendSrv.ts +++ b/packages/grafana-runtime/src/services/backendSrv.ts @@ -143,17 +143,17 @@ export function isFetchError(e: unknown): e is FetchError { * @public */ export interface BackendSrv { - get(url: string, params?: any, requestId?: string): Promise; - delete(url: string, data?: any): Promise; - post(url: string, data?: any): Promise; - patch(url: string, data?: any): Promise; - put(url: string, data?: any): Promise; + get(url: string, params?: any, requestId?: string): Promise; + delete(url: string, data?: any): Promise; + post(url: string, data?: any): Promise; + patch(url: string, data?: any): Promise; + put(url: string, data?: any): Promise; /** * @deprecated Use the fetch function instead. If you prefer to work with a promise * wrap the Observable returned by fetch with the lastValueFrom function. */ - request(options: BackendSrvRequest): Promise; + request(options: BackendSrvRequest): Promise; /** * Special function used to communicate with datasources that will emit core diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 54c955f279a..d0c67af38ab 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -398,19 +398,19 @@ export class BackendSrv implements BackendService { return await this.request({ method: 'GET', url, params, requestId }); } - async delete(url: string, data?: any) { + async delete(url: string, data?: any): Promise { return await this.request({ method: 'DELETE', url, data }); } - async post(url: string, data?: any) { + async post(url: string, data?: any): Promise { return await this.request({ method: 'POST', url, data }); } - async patch(url: string, data: any) { + async patch(url: string, data: any): Promise { return await this.request({ method: 'PATCH', url, data }); } - async put(url: string, data: any) { + async put(url: string, data: any): Promise { return await this.request({ method: 'PUT', url, data }); } diff --git a/public/app/features/plugins/admin/state/reducer.ts b/public/app/features/plugins/admin/state/reducer.ts index 515e9536fdb..75bb63cac6c 100644 --- a/public/app/features/plugins/admin/state/reducer.ts +++ b/public/app/features/plugins/admin/state/reducer.ts @@ -79,7 +79,8 @@ const slice = createSlice({ // TODO .addCase(loadPluginDashboards.fulfilled, (state, action) => { state.isLoadingPluginDashboards = false; - state.dashboards = action.payload; + // eslint-disable-next-line + state.dashboards = action.payload as any; // WritableDraft[],...> }) .addMatcher(isPendingRequest, (state, action) => { state.requests[getOriginalActionType(action.type)] = { diff --git a/public/app/features/search/service/sql.ts b/public/app/features/search/service/sql.ts index 4ebd6b10e5f..5ecb3096831 100644 --- a/public/app/features/search/service/sql.ts +++ b/public/app/features/search/service/sql.ts @@ -97,12 +97,12 @@ export class SQLSearcher implements GrafanaSearcher { // NOTE: the bluge query will find tags within the current results, the SQL based one does not async tags(query: SearchQuery): Promise { - const terms = (await backendSrv.get('/api/dashboards/tags')) as TermCount[]; + const terms = await backendSrv.get('/api/dashboards/tags'); return terms.sort((a, b) => b.count - a.count); } async doAPIQuery(query: APIQuery): Promise { - const rsp = (await backendSrv.get('/api/search', query)) as DashboardSearchHit[]; + const rsp = await backendSrv.get('/api/search', query); // Field values (columnar) const kind: string[] = [];