From 1d6d5cc2cd1fada191db82f7f045851e10908190 Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Fri, 3 May 2024 17:21:37 +0100 Subject: [PATCH] Chore: improve typings (#87306) * some fixes * some more fixes * some canvas fixes * use removeProperty instead * few more * fixy fix * undo changes to ticks for now --- .betterer.results | 93 +++---------------- .../src/services/backendSrv.ts | 4 +- public/app/core/TableModel.ts | 8 +- .../core/components/OptionsUI/registry.tsx | 28 +++--- .../core/components/TagFilter/TagFilter.tsx | 12 +-- .../core/components/TagFilter/TagOption.tsx | 8 +- public/app/core/reducers/root.ts | 2 +- public/app/core/services/backend_srv.ts | 10 +- public/app/core/utils/ConfigProvider.tsx | 4 +- public/app/core/utils/flatten.ts | 5 +- .../app/features/alerting/state/query_part.ts | 2 +- .../app/features/canvas/runtime/element.tsx | 13 +-- public/app/features/canvas/runtime/root.tsx | 6 +- .../saving/DetectChangesWorker.ts | 4 +- .../scene/PanelMenuBehavior.tsx | 18 ++-- .../PanelEditor/OverrideCategoryTitle.tsx | 2 +- .../PanelEditor/getFieldOverrideElements.tsx | 2 +- .../components/LibraryPanelsView/actions.ts | 2 +- public/app/features/library-panels/utils.ts | 4 +- .../manage-dashboards/state/actions.ts | 2 +- .../plugins/admin/hooks/useHistory.tsx | 2 +- 21 files changed, 84 insertions(+), 147 deletions(-) diff --git a/.betterer.results b/.betterer.results index e1ef6ce4716..1d4f74288ee 100644 --- a/.betterer.results +++ b/.betterer.results @@ -696,9 +696,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "7"], [0, 0, 0, "Unexpected any. Specify a different type.", "8"], [0, 0, 0, "Unexpected any. Specify a different type.", "9"], - [0, 0, 0, "Unexpected any. Specify a different type.", "10"], - [0, 0, 0, "Unexpected any. Specify a different type.", "11"], - [0, 0, 0, "Unexpected any. Specify a different type.", "12"] + [0, 0, 0, "Unexpected any. Specify a different type.", "10"] ], "packages/grafana-runtime/src/services/pluginExtensions/getPluginExtensions.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -1063,12 +1061,7 @@ exports[`better eslint`] = { ], "public/app/core/TableModel.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"] + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/app/core/actions/index.ts:5381": [ [0, 0, 0, "Do not re-export imported variable (\`updateNavIndex\`)", "0"], @@ -1103,19 +1096,6 @@ exports[`better eslint`] = { "public/app/core/components/NestedFolderPicker/Trigger.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] ], - "public/app/core/components/OptionsUI/registry.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"], - [0, 0, 0, "Unexpected any. Specify a different type.", "7"], - [0, 0, 0, "Unexpected any. Specify a different type.", "8"], - [0, 0, 0, "Unexpected any. Specify a different type.", "9"], - [0, 0, 0, "Unexpected any. Specify a different type.", "10"] - ], "public/app/core/components/PageHeader/PageHeader.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], [0, 0, 0, "Styles should be written using objects.", "1"] @@ -1157,14 +1137,12 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "2"], [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Styles should be written using objects.", "5"], - [0, 0, 0, "Styles should be written using objects.", "6"] + [0, 0, 0, "Styles should be written using objects.", "4"], + [0, 0, 0, "Styles should be written using objects.", "5"] ], "public/app/core/components/TagFilter/TagOption.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Styles should be written using objects.", "1"], - [0, 0, 0, "Styles should be written using objects.", "2"] + [0, 0, 0, "Styles should be written using objects.", "0"], + [0, 0, 0, "Styles should be written using objects.", "1"] ], "public/app/core/components/TimeSeries/utils.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -1210,23 +1188,16 @@ exports[`better eslint`] = { "public/app/core/navigation/types.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/core/reducers/root.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/core/services/ResponseQueue.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/core/services/backend_srv.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], + [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], + [0, 0, 0, "Unexpected any. Specify a different type.", "2"], [0, 0, 0, "Unexpected any. Specify a different type.", "3"], [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"], - [0, 0, 0, "Unexpected any. Specify a different type.", "7"], - [0, 0, 0, "Unexpected any. Specify a different type.", "8"], - [0, 0, 0, "Unexpected any. Specify a different type.", "9"] + [0, 0, 0, "Unexpected any. Specify a different type.", "5"] ], "public/app/core/services/context_srv.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], @@ -1266,10 +1237,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "17"], [0, 0, 0, "Unexpected any. Specify a different type.", "18"] ], - "public/app/core/utils/ConfigProvider.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] - ], "public/app/core/utils/connectWithReduxStore.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -1293,9 +1260,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "4"], [0, 0, 0, "Unexpected any. Specify a different type.", "5"] ], - "public/app/core/utils/flatten.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/core/utils/object.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], @@ -1394,8 +1358,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "6"], [0, 0, 0, "Unexpected any. Specify a different type.", "7"], [0, 0, 0, "Unexpected any. Specify a different type.", "8"], - [0, 0, 0, "Unexpected any. Specify a different type.", "9"], - [0, 0, 0, "Unexpected any. Specify a different type.", "10"] + [0, 0, 0, "Unexpected any. Specify a different type.", "9"] ], "public/app/features/alerting/state/reducers.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -2234,19 +2197,11 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use export all (\`export * from ...\`)", "3"] ], "public/app/features/canvas/runtime/element.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"], - [0, 0, 0, "Do not use any type assertions.", "4"], - [0, 0, 0, "Do not use any type assertions.", "5"] + [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/features/canvas/runtime/frame.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/canvas/runtime/root.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/canvas/runtime/scene.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], @@ -2346,19 +2301,13 @@ exports[`better eslint`] = { "public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.tsx:5381": [ [0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"] ], - "public/app/features/dashboard-scene/saving/DetectChangesWorker.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] - ], "public/app/features/dashboard-scene/saving/getDashboardChanges.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], [0, 0, 0, "Do not use any type assertions.", "2"] ], "public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"] + [0, 0, 0, "Do not use any type assertions.", "0"] ], "public/app/features/dashboard-scene/serialization/angularMigration.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -2514,8 +2463,7 @@ exports[`better eslint`] = { [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"] ], "public/app/features/dashboard/components/PanelEditor/OverrideCategoryTitle.tsx:5381": [ - [0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] + [0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"] ], "public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx:5381": [ [0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"], @@ -2528,9 +2476,6 @@ exports[`better eslint`] = { "public/app/features/dashboard/components/PanelEditor/VisualizationSelectPane.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] ], - "public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/dashboard/components/PanelEditor/getVisualizationOptions.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -3484,9 +3429,6 @@ exports[`better eslint`] = { "public/app/features/library-panels/components/LibraryPanelsSearch/LibraryPanelsSearch.tsx:5381": [ [0, 0, 0, "\'VerticalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"] ], - "public/app/features/library-panels/components/LibraryPanelsView/actions.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] ], @@ -3502,9 +3444,6 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "4"], [0, 0, 0, "Styles should be written using objects.", "5"] ], - "public/app/features/library-panels/utils.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/live/LiveConnectionWarning.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], [0, 0, 0, "Styles should be written using objects.", "1"] @@ -3655,8 +3594,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "10"], [0, 0, 0, "Unexpected any. Specify a different type.", "11"], [0, 0, 0, "Unexpected any. Specify a different type.", "12"], - [0, 0, 0, "Unexpected any. Specify a different type.", "13"], - [0, 0, 0, "Unexpected any. Specify a different type.", "14"] + [0, 0, 0, "Unexpected any. Specify a different type.", "13"] ], "public/app/features/manage-dashboards/state/reducers.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -3792,9 +3730,6 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "1"], [0, 0, 0, "Styles should be written using objects.", "2"] ], - "public/app/features/plugins/admin/hooks/useHistory.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/plugins/admin/hooks/usePluginInfo.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] ], diff --git a/packages/grafana-runtime/src/services/backendSrv.ts b/packages/grafana-runtime/src/services/backendSrv.ts index bb52f761e5b..634b6553712 100644 --- a/packages/grafana-runtime/src/services/backendSrv.ts +++ b/packages/grafana-runtime/src/services/backendSrv.ts @@ -157,7 +157,7 @@ export interface BackendSrv { * wrap the Observable returned by fetch with the lastValueFrom function, or use the get|delete|post|patch|put methods. * This method is going to be private from Grafana 10. */ - request(options: BackendSrvRequest): Promise; + request(options: BackendSrvRequest): Promise; /** * Special function used to communicate with datasources that will emit core @@ -167,7 +167,7 @@ export interface BackendSrv { * * @deprecated Use the fetch function instead */ - datasourceRequest(options: BackendSrvRequest): Promise>; + datasourceRequest(options: BackendSrvRequest): Promise>; /** * Observable http request interface diff --git a/public/app/core/TableModel.ts b/public/app/core/TableModel.ts index 1ca95fce1fb..19aaa5fb71b 100644 --- a/public/app/core/TableModel.ts +++ b/public/app/core/TableModel.ts @@ -17,7 +17,7 @@ export default class TableModel implements TableData { columns: MutableColumn[]; rows: any[]; type: string; - columnMap: any; + columnMap: Record; refId?: string; meta?: QueryResultMeta; @@ -69,14 +69,14 @@ export default class TableModel implements TableData { } } - addRow(row: any[]) { + addRow(row: unknown[]) { this.rows.push(row); } } // Returns true if both rows have matching non-empty fields as well as matching // indexes where one field is empty and the other is not -function areRowsMatching(columns: Column[], row: any[], otherRow: any[]) { +function areRowsMatching(columns: Column[], row: unknown[], otherRow: unknown[]) { let foundFieldToMatch = false; for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) { if (row[columnIndex] !== undefined && otherRow[columnIndex] !== undefined) { @@ -141,7 +141,7 @@ export function mergeTablesIntoModel(dst?: TableModel, ...tables: TableModel[]): }, []); // Merge rows that have same values for columns - const mergedRows: { [key: string]: any } = {}; + const mergedRows: Record = {}; const compactedRows = flattenedRows.reduce((acc, row, rowIndex) => { if (!mergedRows[rowIndex]) { diff --git a/public/app/core/components/OptionsUI/registry.tsx b/public/app/core/components/OptionsUI/registry.tsx index dfe87a79436..46e30f6bd60 100644 --- a/public/app/core/components/OptionsUI/registry.tsx +++ b/public/app/core/components/OptionsUI/registry.tsx @@ -213,7 +213,7 @@ export const getAllOptionEditors = () => { */ export const getAllStandardFieldConfigs = () => { const category = ['Standard options']; - const displayName: FieldConfigPropertyItem = { + const displayName: FieldConfigPropertyItem = { id: 'displayName', path: 'displayName', name: 'Display name', @@ -229,7 +229,7 @@ export const getAllStandardFieldConfigs = () => { category, }; - const unit: FieldConfigPropertyItem = { + const unit: FieldConfigPropertyItem = { id: 'unit', path: 'unit', name: 'Unit', @@ -247,7 +247,7 @@ export const getAllStandardFieldConfigs = () => { category, }; - const fieldMinMax: FieldConfigPropertyItem = { + const fieldMinMax: FieldConfigPropertyItem = { id: 'fieldMinMax', path: 'fieldMinMax', name: 'Field min/max', @@ -258,13 +258,13 @@ export const getAllStandardFieldConfigs = () => { process: booleanOverrideProcessor, shouldApply: (field) => field.type === FieldType.number, - showIf: (options: FieldConfig) => { + showIf: (options) => { return options.min === undefined || options.max === undefined; }, category, }; - const min: FieldConfigPropertyItem = { + const min: FieldConfigPropertyItem = { id: 'min', path: 'min', name: 'Min', @@ -281,7 +281,7 @@ export const getAllStandardFieldConfigs = () => { category, }; - const max: FieldConfigPropertyItem = { + const max: FieldConfigPropertyItem = { id: 'max', path: 'max', name: 'Max', @@ -299,7 +299,7 @@ export const getAllStandardFieldConfigs = () => { category, }; - const decimals: FieldConfigPropertyItem = { + const decimals: FieldConfigPropertyItem = { id: 'decimals', path: 'decimals', name: 'Decimals', @@ -319,7 +319,7 @@ export const getAllStandardFieldConfigs = () => { category, }; - const noValue: FieldConfigPropertyItem = { + const noValue: FieldConfigPropertyItem = { id: 'noValue', path: 'noValue', name: 'No value', @@ -332,12 +332,12 @@ export const getAllStandardFieldConfigs = () => { settings: { placeholder: '-', }, - // ??? any optionsUi with no value + // ??? FieldConfig optionsUi with no value shouldApply: () => true, category, }; - const links: FieldConfigPropertyItem = { + const links: FieldConfigPropertyItem = { id: 'links', path: 'links', name: 'Data links', @@ -352,7 +352,7 @@ export const getAllStandardFieldConfigs = () => { getItemsCount: (value) => (value ? value.length : 0), }; - const color: FieldConfigPropertyItem = { + const color: FieldConfigPropertyItem = { id: 'color', path: 'color', name: 'Color scheme', @@ -367,7 +367,7 @@ export const getAllStandardFieldConfigs = () => { category, }; - const mappings: FieldConfigPropertyItem = { + const mappings: FieldConfigPropertyItem = { id: 'mappings', path: 'mappings', name: 'Value mappings', @@ -383,7 +383,7 @@ export const getAllStandardFieldConfigs = () => { getItemsCount: (value?) => (value ? value.length : 0), }; - const thresholds: FieldConfigPropertyItem = { + const thresholds: FieldConfigPropertyItem = { id: 'thresholds', path: 'thresholds', name: 'Thresholds', @@ -403,7 +403,7 @@ export const getAllStandardFieldConfigs = () => { getItemsCount: (value) => (value ? value.steps.length : 0), }; - const filterable: FieldConfigPropertyItem<{}, boolean | undefined, {}> = { + const filterable: FieldConfigPropertyItem = { id: 'filterable', path: 'filterable', name: 'Ad-hoc filterable', diff --git a/public/app/core/components/TagFilter/TagFilter.tsx b/public/app/core/components/TagFilter/TagFilter.tsx index 7d6a34ae325..f6148b7efab 100644 --- a/public/app/core/components/TagFilter/TagFilter.tsx +++ b/public/app/core/components/TagFilter/TagFilter.tsx @@ -1,25 +1,19 @@ import { css } from '@emotion/css'; import React, { useCallback, useEffect, useMemo, useState } from 'react'; -import { components } from 'react-select'; +import { components, MultiValueRemoveProps } from 'react-select'; import { escapeStringForRegex, GrafanaTheme2 } from '@grafana/data'; import { Icon, MultiSelect, useStyles2 } from '@grafana/ui'; import { t } from 'app/core/internationalization'; import { TagBadge } from './TagBadge'; -import { TagOption } from './TagOption'; +import { TagOption, TagSelectOption } from './TagOption'; export interface TermCount { term: string; count: number; } -interface TagSelectOption { - value: string; - label: string; - count: number; -} - export interface Props { allowCustomValue?: boolean; formatCreateLabel?: (input: string) => string; @@ -146,7 +140,7 @@ export const TagFilter = ({ MultiValueLabel: () => { return null; // We want the whole tag to be clickable so we use MultiValueRemove instead }, - MultiValueRemove(props: any) { + MultiValueRemove(props: MultiValueRemoveProps) { const { data } = props; return ( diff --git a/public/app/core/components/TagFilter/TagOption.tsx b/public/app/core/components/TagFilter/TagOption.tsx index fbec9997007..38c95655f4a 100644 --- a/public/app/core/components/TagFilter/TagOption.tsx +++ b/public/app/core/components/TagFilter/TagOption.tsx @@ -7,7 +7,13 @@ import { useStyles2 } from '@grafana/ui'; import { TagBadge } from './TagBadge'; -export const TagOption = ({ data, className, label, isFocused, innerProps }: OptionProps) => { +export interface TagSelectOption { + value: string; + label: string; + count: number; +} + +export const TagOption = ({ data, className, label, isFocused, innerProps }: OptionProps) => { const styles = useStyles2(getStyles); return ( diff --git a/public/app/core/reducers/root.ts b/public/app/core/reducers/root.ts index 40c029475c0..54e8c634072 100644 --- a/public/app/core/reducers/root.ts +++ b/public/app/core/reducers/root.ts @@ -71,7 +71,7 @@ export const createRootReducer = () => { ...addedReducers, }); - return (state: any, action: AnyAction) => { + return (state: Parameters[0], action: AnyAction) => { if (action.type !== cleanUpAction.type) { return appReducer(state, action); } diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 559fbff18ff..5fa66df994e 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -107,7 +107,7 @@ export class BackendSrv implements BackendService { } } - async request(options: BackendSrvRequest): Promise { + async request(options: BackendSrvRequest): Promise { return await lastValueFrom(this.fetch(options).pipe(map((response: FetchResponse) => response.data))); } @@ -181,8 +181,8 @@ export class BackendSrv implements BackendService { this.inFlightRequests.next(CANCEL_ALL_REQUESTS_REQUEST_ID); } - async datasourceRequest(options: BackendSrvRequest): Promise { - return lastValueFrom(this.fetch(options)); + async datasourceRequest(options: BackendSrvRequest) { + return lastValueFrom(this.fetch(options)); } private parseRequestOptions(options: BackendSrvRequest): BackendSrvRequest { @@ -371,7 +371,7 @@ export class BackendSrv implements BackendService { return (inputStream) => inputStream.pipe( - retryWhen((attempts: Observable) => + retryWhen((attempts) => attempts.pipe( mergeMap((error, i) => { const firstAttempt = i === 0 && options.retry === 0; @@ -508,7 +508,7 @@ export class BackendSrv implements BackendService { } /** @deprecated */ - search(query: any): Promise { + search(query: Parameters[1]): Promise { return this.get('/api/search', query); } diff --git a/public/app/core/utils/ConfigProvider.tsx b/public/app/core/utils/ConfigProvider.tsx index 9febaaff054..7dafacffb78 100644 --- a/public/app/core/utils/ConfigProvider.tsx +++ b/public/app/core/utils/ConfigProvider.tsx @@ -33,8 +33,8 @@ export const ThemeProvider = ({ children, value }: { children: React.ReactNode; ); }; -export const provideTheme = (component: React.ComponentType, theme: GrafanaTheme2) => { - return function ThemeProviderWrapper(props: any) { +export const provideTheme =

(component: React.ComponentType

, theme: GrafanaTheme2) => { + return function ThemeProviderWrapper(props: P) { return {React.createElement(component, { ...props })}; }; }; diff --git a/public/app/core/utils/flatten.ts b/public/app/core/utils/flatten.ts index 47bdba83fbe..a889abfdb4e 100644 --- a/public/app/core/utils/flatten.ts +++ b/public/app/core/utils/flatten.ts @@ -12,9 +12,8 @@ export default function flatten( let currentDepth = 1; const output: Record = {}; - function step(object: any, prev: string | null) { - Object.keys(object).forEach((key) => { - const value = object[key]; + function step(object: object, prev: string | null) { + Object.entries(object).forEach(([key, value]) => { const isarray = opts?.safe && Array.isArray(value); const type = Object.prototype.toString.call(value); const isobject = type === '[object Object]'; diff --git a/public/app/features/alerting/state/query_part.ts b/public/app/features/alerting/state/query_part.ts index 79fc58ce3bb..ea71ad3946a 100644 --- a/public/app/features/alerting/state/query_part.ts +++ b/public/app/features/alerting/state/query_part.ts @@ -24,7 +24,7 @@ export class QueryPart { params: any[]; text: string; - constructor(part: any, def: any) { + constructor(part: any, def: QueryPartDef) { this.part = part; this.def = def; if (!this.def) { diff --git a/public/app/features/canvas/runtime/element.tsx b/public/app/features/canvas/runtime/element.tsx index 5b2c17f673c..2af902c68a8 100644 --- a/public/app/features/canvas/runtime/element.tsx +++ b/public/app/features/canvas/runtime/element.tsx @@ -191,18 +191,16 @@ export class ElementState implements LayerElement { this.sizeStyle = style; if (this.div) { - for (const key in this.sizeStyle) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - this.div.style[key as any] = (this.sizeStyle as any)[key]; + for (const [key, value] of Object.entries(this.sizeStyle)) { + this.div.style.setProperty(key, value); } // TODO: This is a hack, we should have a better way to handle this const elementType = this.options.type; if (!SVGElements.has(elementType)) { // apply styles to div if it's not an SVG element - for (const key in this.dataStyle) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - this.div.style[key as any] = (this.dataStyle as any)[key]; + for (const [key, value] of Object.entries(this.dataStyle)) { + this.div.style.setProperty(key, value); } } else { // ELEMENT IS SVG @@ -211,8 +209,7 @@ export class ElementState implements LayerElement { // wrapper div element (this.div) doesn't re-render (has static `key` property), // so we have to clean styles manually; for (const key in this.dataStyle) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - this.div.style[key as any] = ''; + this.div.style.removeProperty(key); } } } diff --git a/public/app/features/canvas/runtime/root.tsx b/public/app/features/canvas/runtime/root.tsx index 955d1db57e1..f1ec9d802d1 100644 --- a/public/app/features/canvas/runtime/root.tsx +++ b/public/app/features/canvas/runtime/root.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import { CanvasElementOptions, CanvasFrameOptions } from 'app/features/canvas'; +import { CanvasFrameOptions } from 'app/features/canvas'; import { FrameState } from './frame'; import { Scene } from './scene'; @@ -24,9 +24,9 @@ export class RootElement extends FrameState { } // root type can not change - onChange(options: CanvasElementOptions) { + onChange(options: CanvasFrameOptions) { this.revId++; - this.options = { ...options } as CanvasFrameOptions; + this.options = { ...options }; this.changeCallback(); } diff --git a/public/app/features/dashboard-scene/saving/DetectChangesWorker.ts b/public/app/features/dashboard-scene/saving/DetectChangesWorker.ts index e8a3f2f6abe..2d7cb6f8386 100644 --- a/public/app/features/dashboard-scene/saving/DetectChangesWorker.ts +++ b/public/app/features/dashboard-scene/saving/DetectChangesWorker.ts @@ -1,3 +1,5 @@ +import { Dashboard } from '@grafana/schema'; + import { getDashboardChanges } from './getDashboardChanges'; function _debounce(f: (...args: T[]) => void, timeout: number) { @@ -10,7 +12,7 @@ function _debounce(f: (...args: T[]) => void, timeout: number) { }; } -self.onmessage = _debounce((e: MessageEvent<{ initial: any; changed: any }>) => { +self.onmessage = _debounce((e: MessageEvent<{ initial: Dashboard; changed: Dashboard }>) => { const result = getDashboardChanges(e.data.initial, e.data.changed, false, false, false); self.postMessage(result); }, 500); diff --git a/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx b/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx index cb0d4aadc15..0aecf323e73 100644 --- a/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx +++ b/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx @@ -1,5 +1,6 @@ import { InterpolateFunction, + LinkModel, PanelMenuItem, PanelPlugin, PluginExtensionPanelContext, @@ -331,13 +332,16 @@ export function getPanelLinks(panel: VizPanel) { const panelLinks = linkSupplier.getLinks(interpolate); - return panelLinks.map((panelLink) => ({ - ...panelLink, - onClick: (e: any, origin: any) => { - DashboardInteractions.panelLinkClicked({ has_multiple_links: panelLinks.length > 1 }); - panelLink.onClick?.(e, origin); - }, - })); + return panelLinks.map((panelLink) => { + const updatedLink: LinkModel = { + ...panelLink, + onClick: (e, origin) => { + DashboardInteractions.panelLinkClicked({ has_multiple_links: panelLinks.length > 1 }); + panelLink.onClick?.(e, origin); + }, + }; + return updatedLink; + }); } function createExtensionContext(panel: VizPanel, dashboard: DashboardScene): PluginExtensionPanelContext { diff --git a/public/app/features/dashboard/components/PanelEditor/OverrideCategoryTitle.tsx b/public/app/features/dashboard/components/PanelEditor/OverrideCategoryTitle.tsx index 1474507224b..32d3847dd5c 100644 --- a/public/app/features/dashboard/components/PanelEditor/OverrideCategoryTitle.tsx +++ b/public/app/features/dashboard/components/PanelEditor/OverrideCategoryTitle.tsx @@ -8,7 +8,7 @@ import { FieldMatcherUIRegistryItem } from '@grafana/ui/src/components/MatchersU interface Props { isExpanded: boolean; registry: FieldConfigOptionsRegistry; - matcherUi: FieldMatcherUIRegistryItem; + matcherUi: FieldMatcherUIRegistryItem; override: ConfigOverrideRule; overrideName: string; onOverrideRemove: () => void; diff --git a/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx b/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx index eca2153ba77..26035fb57ba 100644 --- a/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx +++ b/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx @@ -105,7 +105,7 @@ export function getFieldOverrideCategories( }, }); - const onMatcherConfigChange = (options: any) => { + const onMatcherConfigChange = (options: unknown) => { override.matcher.options = options; onOverrideChange(idx, override); }; diff --git a/public/app/features/library-panels/components/LibraryPanelsView/actions.ts b/public/app/features/library-panels/components/LibraryPanelsView/actions.ts index 3578a44064c..833150f3419 100644 --- a/public/app/features/library-panels/components/LibraryPanelsView/actions.ts +++ b/public/app/features/library-panels/components/LibraryPanelsView/actions.ts @@ -100,7 +100,7 @@ export function deleteLibraryPanel(uid: string, args: SearchArgs): DispatchResul } export function asyncDispatcher(dispatch: Dispatch) { - return function (action: any) { + return function (action: AnyAction | DispatchResult) { if (action instanceof Function) { return action(dispatch); } diff --git a/public/app/features/library-panels/utils.ts b/public/app/features/library-panels/utils.ts index 533f488ff04..874bcb8aa54 100644 --- a/public/app/features/library-panels/utils.ts +++ b/public/app/features/library-panels/utils.ts @@ -1,7 +1,7 @@ import { PanelModel } from '../dashboard/state'; import { addLibraryPanel, updateLibraryPanel } from './state/api'; -import { LibraryElementDTO } from './types'; +import { LibraryElementDTO, PanelModelWithLibraryPanel } from './types'; export async function saveAndRefreshLibraryPanel(panel: PanelModel, folderUid: string): Promise { const panelSaveModel = toPanelSaveModel(panel); @@ -34,7 +34,7 @@ function updatePanelModelWithUpdate(panel: PanelModel, updated: LibraryElementDT panel.refresh(); } -function saveOrUpdateLibraryPanel(panel: any, folderUid: string): Promise { +function saveOrUpdateLibraryPanel(panel: PanelModelWithLibraryPanel, folderUid: string): Promise { if (!panel.libraryPanel) { return Promise.reject(); } diff --git a/public/app/features/manage-dashboards/state/actions.ts b/public/app/features/manage-dashboards/state/actions.ts index 8d0cae65376..40cdeb80270 100644 --- a/public/app/features/manage-dashboards/state/actions.ts +++ b/public/app/features/manage-dashboards/state/actions.ts @@ -212,7 +212,7 @@ export function importDashboard(importDashboardForm: ImportDashboardDTO): ThunkR }); }); - importDashboardForm.constants?.forEach((constant: any, index: number) => { + importDashboardForm.constants?.forEach((constant, index) => { const input = inputs.constants[index]; inputsToPersist.push({ diff --git a/public/app/features/plugins/admin/hooks/useHistory.tsx b/public/app/features/plugins/admin/hooks/useHistory.tsx index 5b1c501c39f..07f24e80825 100644 --- a/public/app/features/plugins/admin/hooks/useHistory.tsx +++ b/public/app/features/plugins/admin/hooks/useHistory.tsx @@ -2,7 +2,7 @@ import { locationService } from '@grafana/runtime'; export const useHistory = () => { return { - push: ({ query }: any) => { + push: ({ query }: { query: Parameters[0] }) => { locationService.partial(query); }, };