From 0c44a6f9bb9cf547e16cec3db398d9cfd8bc534c Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Wed, 13 Sep 2023 09:17:07 +0100 Subject: [PATCH] =?UTF-8?q?Chore:=20Improve=20typings=20=F0=9F=A7=B9=20=20?= =?UTF-8?q?(#74599)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * various type fixes * candlestick panel type fixes * few more fixes * some fixes * more :) * moar! * undo change to SilencesFilter * undo change to configureStore --- .betterer.results | 306 +++--------------- .../grafana-data/src/datetime/rangeutil.ts | 2 +- .../grafana-data/src/events/EventBus.test.ts | 2 +- packages/grafana-data/src/events/EventBus.ts | 2 +- .../grafana-data/src/field/fieldOverrides.ts | 6 +- .../standardFieldConfigEditorRegistry.ts | 2 +- .../src/panel/getPanelOptionsWithDefaults.ts | 21 +- .../transformations/matchers/predicates.ts | 16 +- .../transformers/ensureColumns.ts | 2 +- .../transformations/transformers/histogram.ts | 2 +- packages/grafana-data/src/utils/location.ts | 2 +- .../src/utils/testdata/testTheme.ts | 12 - .../grafana-data/src/utils/valueMappings.ts | 6 +- .../grafana-data/src/vector/AsNumberVector.ts | 2 +- .../src/vector/BinaryOperationVector.ts | 2 +- .../grafana-data/src/vector/ConstantVector.ts | 2 +- .../src/vector/FormattedVector.ts | 2 +- .../grafana-data/src/vector/IndexVector.ts | 2 +- .../src/services/backendSrv.ts | 8 +- .../core/components/TagFilter/TagFilter.tsx | 4 +- public/app/core/services/backend_srv.ts | 14 +- public/app/core/specs/time_series.test.ts | 4 +- public/app/core/utils/query.ts | 10 +- .../unified/PanelAlertTabContent.test.tsx | 7 +- .../unified/components/Expression.tsx | 6 +- .../components/receivers/TemplateForm.tsx | 3 +- .../receivers/form/TestContactPointModal.tsx | 8 +- .../components/rule-editor/AlertRuleForm.tsx | 2 +- .../rules/RuleDetailsDataSources.tsx | 19 +- .../unified/hooks/useFilteredRules.ts | 4 +- .../unified/hooks/useGroupedAlerts.ts | 12 +- .../alerting/unified/utils/amroutes.ts | 6 +- .../alerting/unified/utils/receiver-form.ts | 4 +- .../features/alerting/unified/utils/rules.ts | 23 +- .../app/features/canvas/runtime/element.tsx | 4 +- public/app/features/canvas/runtime/frame.tsx | 2 +- .../dashboard-scene/utils/test-utils.ts | 2 +- .../components/VersionHistory/utils.ts | 4 +- .../features/dashboard/utils/panelMerge.ts | 2 +- .../DashboardQueryRunner/SnapshotWorker.ts | 4 +- .../app/features/variables/inspect/utils.ts | 84 +++-- .../pickers/OptionsPicker/reducer.test.ts | 2 +- .../app/features/variables/query/actions.ts | 29 +- .../app/features/variables/state/actions.ts | 4 +- .../prometheus/components/PromQueryField.tsx | 4 +- .../querybuilder/binaryScalarOperations.ts | 19 +- .../plugins/datasource/tempo/testResponse.ts | 75 +++-- .../tempo/traceql/TraceQLEditor.tsx | 5 +- .../datasource/tempo/traceql/traceql.ts | 5 +- .../components/StreamingClientEditor.tsx | 5 +- .../testdata/testData/serviceMapResponse.ts | 6 +- .../panel/candlestick/CandlestickPanel.tsx | 6 +- .../app/plugins/panel/candlestick/module.tsx | 14 +- public/app/plugins/panel/candlestick/utils.ts | 32 +- .../app/plugins/panel/piechart/suggestions.ts | 10 +- .../app/plugins/panel/stat/StatMigrations.ts | 2 +- .../panel/state-timeline/migrations.ts | 12 +- public/app/plugins/panel/table/module.tsx | 4 +- .../panel/text/textPanelMigrationHandler.ts | 4 +- .../plugins/panel/timeseries/migrations.ts | 8 +- .../plugins/panel/timeseries/suggestions.ts | 11 +- public/app/plugins/panel/trend/suggestions.ts | 11 +- 62 files changed, 332 insertions(+), 563 deletions(-) delete mode 100644 packages/grafana-data/src/utils/testdata/testTheme.ts diff --git a/.betterer.results b/.betterer.results index 95b94a48007..3f9a9419a91 100644 --- a/.betterer.results +++ b/.betterer.results @@ -188,17 +188,12 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "8"] ], "packages/grafana-data/src/datetime/rangeutil.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"] + [0, 0, 0, "Do not use any type assertions.", "0"] ], "packages/grafana-data/src/datetime/timezones.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"] ], - "packages/grafana-data/src/events/EventBus.test.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "packages/grafana-data/src/events/EventBus.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -224,10 +219,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "3"] ], "packages/grafana-data/src/field/fieldOverrides.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.", "0"] ], "packages/grafana-data/src/field/overrides/processors.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -256,8 +248,7 @@ exports[`better eslint`] = { [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.", "6"] ], "packages/grafana-data/src/geo/layer.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -277,15 +268,7 @@ exports[`better eslint`] = { "packages/grafana-data/src/panel/getPanelOptionsWithDefaults.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.", "7"], - [0, 0, 0, "Do not use any type assertions.", "8"], - [0, 0, 0, "Unexpected any. Specify a different type.", "9"], - [0, 0, 0, "Do not use any type assertions.", "10"] + [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], "packages/grafana-data/src/panel/registryFactories.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], @@ -307,16 +290,6 @@ exports[`better eslint`] = { "packages/grafana-data/src/transformations/fieldReducer.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "packages/grafana-data/src/transformations/matchers/predicates.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.", "7"] - ], "packages/grafana-data/src/transformations/matchers/valueMatchers/types.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] @@ -334,9 +307,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "3"], [0, 0, 0, "Unexpected any. Specify a different type.", "4"] ], - "packages/grafana-data/src/transformations/transformers/ensureColumns.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "packages/grafana-data/src/transformations/transformers/groupBy.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] @@ -346,9 +316,7 @@ exports[`better eslint`] = { ], "packages/grafana-data/src/transformations/transformers/histogram.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "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.", "1"] ], "packages/grafana-data/src/transformations/transformers/joinDataFrames.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -691,12 +659,7 @@ exports[`better eslint`] = { "packages/grafana-data/src/utils/location.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "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"] - ], - "packages/grafana-data/src/utils/testdata/testTheme.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"] + [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], "packages/grafana-data/src/utils/url.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -715,13 +678,10 @@ exports[`better eslint`] = { [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, "Unexpected any. Specify a different type.", "4"], + [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.", "6"], - [0, 0, 0, "Unexpected any. Specify a different type.", "7"], - [0, 0, 0, "Do not use any type assertions.", "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.", "7"] ], "packages/grafana-data/src/vector/AppendedVectors.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -733,23 +693,15 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], - "packages/grafana-data/src/vector/AsNumberVector.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], - "packages/grafana-data/src/vector/BinaryOperationVector.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "packages/grafana-data/src/vector/CircularVector.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "packages/grafana-data/src/vector/ConstantVector.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, "Unexpected any. Specify a different type.", "0"] ], "packages/grafana-data/src/vector/FormattedVector.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, "Unexpected any. Specify a different type.", "0"] ], "packages/grafana-data/src/vector/FunctionalVector.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -764,9 +716,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "9"], [0, 0, 0, "Unexpected any. Specify a different type.", "10"] ], - "packages/grafana-data/src/vector/IndexVector.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "packages/grafana-data/src/vector/SortedVector.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], @@ -814,12 +763,7 @@ exports[`better eslint`] = { [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.", "13"], - [0, 0, 0, "Unexpected any. Specify a different type.", "14"], - [0, 0, 0, "Unexpected any. Specify a different type.", "15"], - [0, 0, 0, "Unexpected any. Specify a different type.", "16"], - [0, 0, 0, "Unexpected any. Specify a different type.", "17"] + [0, 0, 0, "Unexpected any. Specify a different type.", "12"] ], "packages/grafana-runtime/src/services/live.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -1422,9 +1366,7 @@ 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, "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.", "4"] ], "public/app/core/components/TagFilter/TagOption.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -1456,15 +1398,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.", "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.", "15"], - [0, 0, 0, "Unexpected any. Specify a different type.", "16"], - [0, 0, 0, "Unexpected any. Specify a different type.", "17"] + [0, 0, 0, "Unexpected any. Specify a different type.", "9"] ], "public/app/core/services/context_srv.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], @@ -1484,9 +1418,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/core/specs/time_series.test.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.", "0"] ], "public/app/core/time_series2.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -1557,9 +1489,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "3"], [0, 0, 0, "Unexpected any. Specify a different type.", "4"] ], - "public/app/core/utils/query.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/core/utils/richHistory.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], @@ -1679,12 +1608,6 @@ exports[`better eslint`] = { "public/app/features/alerting/unified/AlertsFolderView.test.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/features/alerting/unified/PanelAlertTabContent.test.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"] - ], "public/app/features/alerting/unified/PanelAlertTabContent.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] ], @@ -1708,10 +1631,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"] ], - "public/app/features/alerting/unified/components/Expression.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"] - ], "public/app/features/alerting/unified/components/alert-groups/AlertGroupFilter.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], @@ -1725,10 +1644,6 @@ exports[`better eslint`] = { "public/app/features/alerting/unified/components/contact-points/ContactPoints.v2.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/alerting/unified/components/receivers/TemplateForm.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] - ], "public/app/features/alerting/unified/components/receivers/form/ChannelOptions.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], @@ -1740,10 +1655,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "2"], [0, 0, 0, "Do not use any type assertions.", "3"] ], - "public/app/features/alerting/unified/components/receivers/form/TestContactPointModal.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"] - ], "public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -1762,9 +1673,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], - "public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/alerting/unified/components/rule-editor/AnnotationKeyInput.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], @@ -1780,9 +1688,6 @@ exports[`better eslint`] = { "public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] ], - "public/app/features/alerting/unified/components/rules/RuleDetailsDataSources.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/alerting/unified/components/silences/SilencesEditor.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], @@ -1795,15 +1700,6 @@ exports[`better eslint`] = { "public/app/features/alerting/unified/hooks/useControlledFieldArray.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/features/alerting/unified/hooks/useFilteredRules.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"] - ], - "public/app/features/alerting/unified/hooks/useGroupedAlerts.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"] - ], "public/app/features/alerting/unified/mocks.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], @@ -1825,10 +1721,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], - "public/app/features/alerting/unified/utils/amroutes.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"] - ], "public/app/features/alerting/unified/utils/misc.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -1838,9 +1730,7 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "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, "Unexpected any. Specify a different type.", "5"] + [0, 0, 0, "Unexpected any. Specify a different type.", "3"] ], "public/app/features/alerting/unified/utils/redux.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -1861,8 +1751,7 @@ exports[`better eslint`] = { [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, "Do not use any type assertions.", "4"] ], "public/app/features/annotations/events_processing.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -1882,19 +1771,16 @@ exports[`better eslint`] = { "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, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Do not use any type assertions.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Do not use any type assertions.", "6"], - [0, 0, 0, "Unexpected any. Specify a different type.", "7"], - [0, 0, 0, "Do not use any type assertions.", "8"], - [0, 0, 0, "Unexpected any. Specify a different type.", "9"], - [0, 0, 0, "Do not use any type assertions.", "10"] + [0, 0, 0, "Unexpected any. Specify a different type.", "2"], + [0, 0, 0, "Do not use any type assertions.", "3"], + [0, 0, 0, "Unexpected any. Specify a different type.", "4"], + [0, 0, 0, "Do not use any type assertions.", "5"], + [0, 0, 0, "Unexpected any. Specify a different type.", "6"], + [0, 0, 0, "Do not use any type assertions.", "7"], + [0, 0, 0, "Unexpected any. Specify a different type.", "8"] ], "public/app/features/canvas/runtime/frame.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"] + [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"] @@ -1920,9 +1806,7 @@ exports[`better eslint`] = { "public/app/features/dashboard-scene/utils/test-utils.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Do not use any type assertions.", "4"] + [0, 0, 0, "Do not use any type assertions.", "2"] ], "public/app/features/dashboard/components/AddPanelWidget/AddPanelWidget.test.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -2078,9 +1962,7 @@ exports[`better eslint`] = { ], "public/app/features/dashboard/components/VersionHistory/utils.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.", "1"] ], "public/app/features/dashboard/containers/DashboardPage.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], @@ -2291,10 +2173,9 @@ exports[`better eslint`] = { ], "public/app/features/dashboard/utils/panelMerge.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"] + [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.", "3"] ], "public/app/features/datasources/components/BasicSettings.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] @@ -2728,9 +2609,6 @@ exports[`better eslint`] = { "public/app/features/query/state/DashboardQueryRunner/PublicAnnotationsDataSource.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/query/state/DashboardQueryRunner/SnapshotWorker.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/query/state/DashboardQueryRunner/testHelpers.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -3076,18 +2954,13 @@ exports[`better eslint`] = { [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, "Do not use any type assertions.", "3"], + [0, 0, 0, "Unexpected any. Specify a different type.", "3"], [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Do not use any type assertions.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"], - [0, 0, 0, "Unexpected any. Specify a different type.", "7"], - [0, 0, 0, "Do not use any type assertions.", "8"], - [0, 0, 0, "Do not use any type assertions.", "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, "Do not use any type assertions.", "13"], - [0, 0, 0, "Do not use any type assertions.", "14"] + [0, 0, 0, "Unexpected any. Specify a different type.", "5"], + [0, 0, 0, "Do not use any type assertions.", "6"], + [0, 0, 0, "Do not use any type assertions.", "7"], + [0, 0, 0, "Unexpected any. Specify a different type.", "8"], + [0, 0, 0, "Unexpected any. Specify a different type.", "9"] ], "public/app/features/variables/interval/reducer.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -3109,8 +2982,7 @@ exports[`better eslint`] = { [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.", "13"] + [0, 0, 0, "Unexpected any. Specify a different type.", "12"] ], "public/app/features/variables/pickers/shared/VariableInput.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -3144,8 +3016,7 @@ 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, "Do not use any type assertions.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"] + [0, 0, 0, "Unexpected any. Specify a different type.", "4"] ], "public/app/features/variables/query/operators.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -3217,9 +3088,8 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "10"], [0, 0, 0, "Unexpected any. Specify a different type.", "11"], [0, 0, 0, "Unexpected any. Specify a different type.", "12"], - [0, 0, 0, "Do not use any type assertions.", "13"], - [0, 0, 0, "Unexpected any. Specify a different type.", "14"], - [0, 0, 0, "Unexpected any. Specify a different type.", "15"] + [0, 0, 0, "Unexpected any. Specify a different type.", "13"], + [0, 0, 0, "Unexpected any. Specify a different type.", "14"] ], "public/app/features/variables/state/keyedVariablesReducer.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -3996,9 +3866,7 @@ exports[`better eslint`] = { "public/app/plugins/datasource/prometheus/components/PromQueryField.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, "Do not use any type assertions.", "4"] + [0, 0, 0, "Do not use any type assertions.", "2"] ], "public/app/plugins/datasource/prometheus/components/PrometheusMetricsBrowser.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], @@ -4129,8 +3997,7 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "4"] ], "public/app/plugins/datasource/prometheus/querybuilder/binaryScalarOperations.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] + [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/plugins/datasource/prometheus/querybuilder/components/LabelFilterItem.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"], @@ -4306,16 +4173,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "8"], [0, 0, 0, "Unexpected any. Specify a different type.", "9"] ], - "public/app/plugins/datasource/tempo/testResponse.ts:5381": [ - [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.", "3"] - ], - "public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"] - ], "public/app/plugins/datasource/tempo/traceql/autocomplete.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] @@ -4351,9 +4208,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], - "public/app/plugins/datasource/testdata/components/StreamingClientEditor.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/plugins/datasource/testdata/datasource.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] @@ -4366,10 +4220,6 @@ exports[`better eslint`] = { "public/app/plugins/datasource/testdata/runStreams.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/plugins/datasource/testdata/testData/serviceMapResponse.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"] - ], "public/app/plugins/datasource/zipkin/QueryField.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], @@ -4433,29 +4283,7 @@ exports[`better eslint`] = { ], "public/app/plugins/panel/candlestick/CandlestickPanel.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"] - ], - "public/app/plugins/panel/candlestick/module.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "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"] - ], - "public/app/plugins/panel/candlestick/utils.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "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, "Do not use any type assertions.", "6"], - [0, 0, 0, "Do not use any type assertions.", "7"], - [0, 0, 0, "Do not use any type assertions.", "8"], - [0, 0, 0, "Do not use any type assertions.", "9"], - [0, 0, 0, "Do not use any type assertions.", "10"], - [0, 0, 0, "Do not use any type assertions.", "11"] + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/app/plugins/panel/canvas/editor/connectionEditor.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -5026,24 +4854,13 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], - "public/app/plugins/panel/piechart/suggestions.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] - ], "public/app/plugins/panel/stat/StatMigrations.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, "Do not use any type assertions.", "2"] + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/app/plugins/panel/state-timeline/migrations.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, "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, "Do not use any type assertions.", "6"], - [0, 0, 0, "Do not use any type assertions.", "7"] + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/app/plugins/panel/table-old/column_options.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -5165,24 +4982,15 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "6"], [0, 0, 0, "Unexpected any. Specify a different type.", "7"] ], - "public/app/plugins/panel/table/module.tsx:5381": [ - [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.", "3"] - ], "public/app/plugins/panel/text/TextPanelEditor.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/plugins/panel/text/textPanelMigrationHandler.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, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"] + [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/plugins/panel/timeseries/migrations.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, "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.", "3"], [0, 0, 0, "Do not use any type assertions.", "4"], @@ -5190,17 +4998,13 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "6"], [0, 0, 0, "Unexpected any. Specify a different type.", "7"], [0, 0, 0, "Do not use any type assertions.", "8"], - [0, 0, 0, "Do not use any type assertions.", "9"], - [0, 0, 0, "Unexpected any. Specify a different type.", "10"], - [0, 0, 0, "Do not use any type assertions.", "11"], - [0, 0, 0, "Unexpected any. Specify a different type.", "12"], - [0, 0, 0, "Do not use any type assertions.", "13"], + [0, 0, 0, "Unexpected any. Specify a different type.", "9"], + [0, 0, 0, "Do not use any type assertions.", "10"], + [0, 0, 0, "Unexpected any. Specify a different type.", "11"], + [0, 0, 0, "Do not use any type assertions.", "12"], + [0, 0, 0, "Unexpected any. Specify a different type.", "13"], [0, 0, 0, "Unexpected any. Specify a different type.", "14"], - [0, 0, 0, "Do not use any type assertions.", "15"], - [0, 0, 0, "Unexpected any. Specify a different type.", "16"], - [0, 0, 0, "Unexpected any. Specify a different type.", "17"], - [0, 0, 0, "Unexpected any. Specify a different type.", "18"], - [0, 0, 0, "Unexpected any. Specify a different type.", "19"] + [0, 0, 0, "Unexpected any. Specify a different type.", "15"] ], "public/app/plugins/panel/timeseries/plugins/ExemplarMarker.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] @@ -5208,12 +5012,6 @@ exports[`better eslint`] = { "public/app/plugins/panel/timeseries/plugins/annotations/AnnotationEditor.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/plugins/panel/timeseries/suggestions.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], - "public/app/plugins/panel/trend/suggestions.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/plugins/panel/xychart/AutoEditor.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], diff --git a/packages/grafana-data/src/datetime/rangeutil.ts b/packages/grafana-data/src/datetime/rangeutil.ts index 00ff5f81c97..c4f514b6735 100644 --- a/packages/grafana-data/src/datetime/rangeutil.ts +++ b/packages/grafana-data/src/datetime/rangeutil.ts @@ -328,7 +328,7 @@ export function describeInterval(str: string) { ); } return { - sec: (intervals_in_seconds as any)[matches[2]] as number, + sec: intervals_in_seconds[matches[2] as keyof typeof intervals_in_seconds], type: matches[2], count: parseInt(matches[1], 10), }; diff --git a/packages/grafana-data/src/events/EventBus.test.ts b/packages/grafana-data/src/events/EventBus.test.ts index eaf69d9b499..72716fa7eef 100644 --- a/packages/grafana-data/src/events/EventBus.test.ts +++ b/packages/grafana-data/src/events/EventBus.test.ts @@ -51,7 +51,7 @@ describe('EventBus', () => { it('can add sources to the source path', () => { const bus = new EventBusSrv(); const busWithSource = bus.newScopedBus('foo'); - expect((busWithSource as any).path).toEqual(['foo']); + expect(busWithSource.path).toEqual(['foo']); }); it('adds the source to the event payload', () => { diff --git a/packages/grafana-data/src/events/EventBus.ts b/packages/grafana-data/src/events/EventBus.ts index 2caf8a5c807..106ff4da074 100644 --- a/packages/grafana-data/src/events/EventBus.ts +++ b/packages/grafana-data/src/events/EventBus.ts @@ -48,7 +48,7 @@ export class EventBusSrv implements EventBus, LegacyEmitter { }); } - newScopedBus(key: string, filter?: EventFilterOptions): EventBus { + newScopedBus(key: string, filter?: EventFilterOptions): ScopedEventBus { return new ScopedEventBus([key], this, filter); } diff --git a/packages/grafana-data/src/field/fieldOverrides.ts b/packages/grafana-data/src/field/fieldOverrides.ts index d653001541a..6fc79b771fd 100644 --- a/packages/grafana-data/src/field/fieldOverrides.ts +++ b/packages/grafana-data/src/field/fieldOverrides.ts @@ -258,7 +258,7 @@ function cachingDisplayProcessor(disp: DisplayProcessor, maxCacheSize = 2500): D caches.set(i, new Map()); } - return (value: any, decimals?: DecimalCount) => { + return (value: unknown, decimals?: DecimalCount) => { let cache = caches.get(decimals ?? -1)!; let v = cache.get(value); @@ -342,8 +342,8 @@ export function setFieldConfigDefaults(config: FieldConfig, defaults: FieldConfi } function processFieldConfigValue( - destination: Record, // it's mutable - source: Record, + destination: Record, // it's mutable + source: Record, fieldConfigProperty: FieldConfigPropertyItem, context: FieldOverrideEnv ) { diff --git a/packages/grafana-data/src/field/standardFieldConfigEditorRegistry.ts b/packages/grafana-data/src/field/standardFieldConfigEditorRegistry.ts index f99d8decb8e..75f0a32f94d 100644 --- a/packages/grafana-data/src/field/standardFieldConfigEditorRegistry.ts +++ b/packages/grafana-data/src/field/standardFieldConfigEditorRegistry.ts @@ -29,4 +29,4 @@ export interface StandardEditorsRegistryItem exte } export const standardFieldConfigEditorRegistry = new FieldConfigOptionsRegistry(); -export const standardEditorsRegistry = new Registry>(); +export const standardEditorsRegistry = new Registry(); diff --git a/packages/grafana-data/src/panel/getPanelOptionsWithDefaults.ts b/packages/grafana-data/src/panel/getPanelOptionsWithDefaults.ts index b461d007d96..1061054d1d1 100644 --- a/packages/grafana-data/src/panel/getPanelOptionsWithDefaults.ts +++ b/packages/grafana-data/src/panel/getPanelOptionsWithDefaults.ts @@ -37,16 +37,12 @@ export function getPanelOptionsWithDefaults({ currentFieldConfig, isAfterPluginChange, }: Props): OptionDefaults { - const optionsWithDefaults = mergeWith( - {}, - plugin.defaults, - currentOptions || {}, - (objValue: any, srcValue: any): any => { - if (isArray(srcValue)) { - return srcValue; - } + const optionsWithDefaults = mergeWith({}, plugin.defaults, currentOptions || {}, (objValue, srcValue) => { + if (isArray(srcValue)) { + return srcValue; } - ); + return; + }); const fieldConfigWithDefaults = applyFieldConfigDefaults(currentFieldConfig, plugin); const fieldConfigWithOptimalColorMode = adaptFieldColorMode(plugin, fieldConfigWithDefaults, isAfterPluginChange); @@ -62,10 +58,11 @@ function applyFieldConfigDefaults(existingFieldConfig: FieldConfigSource, plugin {}, pluginDefaults.defaults, existingFieldConfig ? existingFieldConfig.defaults : {}, - (objValue: any, srcValue: any): any => { + (objValue, srcValue) => { if (isArray(srcValue)) { return srcValue; } + return; } ), overrides: existingFieldConfig?.overrides ?? [], @@ -86,7 +83,7 @@ function applyFieldConfigDefaults(existingFieldConfig: FieldConfigSource, plugin for (const override of result.overrides) { for (const property of override.properties) { if (property.id === 'thresholds') { - fixThresholds(property.value as ThresholdsConfig); + fixThresholds(property.value); } } } @@ -157,7 +154,7 @@ function adaptFieldColorMode( const color = plugin.fieldConfigRegistry.getIfExists(FieldConfigProperty.Color); if (color && color.settings) { - const colorSettings = color.settings as FieldColorConfigSettings; + const colorSettings: FieldColorConfigSettings = color.settings; const mode = fieldColorModeRegistry.getIfExists(fieldConfig.defaults.color?.mode); // When no support fo value colors, use classic palette diff --git a/packages/grafana-data/src/transformations/matchers/predicates.ts b/packages/grafana-data/src/transformations/matchers/predicates.ts index 386d87b69fe..ef26e05be1e 100644 --- a/packages/grafana-data/src/transformations/matchers/predicates.ts +++ b/packages/grafana-data/src/transformations/matchers/predicates.ts @@ -205,11 +205,11 @@ const alwaysFieldMatcherInfo: FieldMatcherInfo = { name: 'All Fields', description: 'Always Match', - get: (option: any) => { + get: (_option) => { return alwaysFieldMatcher; }, - getOptionsDisplayText: (options: any) => { + getOptionsDisplayText: (_options) => { return 'Always'; }, }; @@ -219,11 +219,11 @@ const alwaysFrameMatcherInfo: FrameMatcherInfo = { name: 'All Frames', description: 'Always Match', - get: (option: any) => { + get: (_option) => { return alwaysFrameMatcher; }, - getOptionsDisplayText: (options: any) => { + getOptionsDisplayText: (_options) => { return 'Always'; }, }; @@ -234,11 +234,11 @@ const neverFieldMatcherInfo: FieldMatcherInfo = { description: 'Never Match', excludeFromPicker: true, - get: (option: any) => { + get: (_option) => { return neverFieldMatcher; }, - getOptionsDisplayText: (options: any) => { + getOptionsDisplayText: (_options) => { return 'Never'; }, }; @@ -248,11 +248,11 @@ const neverFrameMatcherInfo: FrameMatcherInfo = { name: 'No Frames', description: 'Never Match', - get: (option: any) => { + get: (_option) => { return neverFrameMatcher; }, - getOptionsDisplayText: (options: any) => { + getOptionsDisplayText: (_options) => { return 'Never'; }, }; diff --git a/packages/grafana-data/src/transformations/transformers/ensureColumns.ts b/packages/grafana-data/src/transformations/transformers/ensureColumns.ts index 4968336c236..daaefe53e10 100644 --- a/packages/grafana-data/src/transformations/transformers/ensureColumns.ts +++ b/packages/grafana-data/src/transformations/transformers/ensureColumns.ts @@ -15,7 +15,7 @@ export const ensureColumnsTransformer: SynchronousDataTransformerInfo = { operator: (options, ctx) => (source) => source.pipe(map((data) => ensureColumnsTransformer.transformer(options, ctx)(data))), - transformer: (_options: any, ctx) => (frames: DataFrame[]) => { + transformer: (_options, ctx) => (frames: DataFrame[]) => { // Assume timeseries should first be joined by time const timeFieldName = findConsistentTimeFieldName(frames); diff --git a/packages/grafana-data/src/transformations/transformers/histogram.ts b/packages/grafana-data/src/transformations/transformers/histogram.ts index 0b79a4d9d5d..cba17782e67 100644 --- a/packages/grafana-data/src/transformations/transformers/histogram.ts +++ b/packages/grafana-data/src/transformations/transformers/histogram.ts @@ -361,7 +361,7 @@ function histogram( vals: number[], getBucket: (v: number) => number, filterOut?: any[] | null, - sort?: ((a: any, b: any) => number) | null + sort?: ((a: number, b: number) => number) | null ) { let hist = new Map(); diff --git a/packages/grafana-data/src/utils/location.ts b/packages/grafana-data/src/utils/location.ts index a0d70396f19..d6b851c9ae1 100644 --- a/packages/grafana-data/src/utils/location.ts +++ b/packages/grafana-data/src/utils/location.ts @@ -5,7 +5,7 @@ import { GrafanaConfig, RawTimeRange, ScopedVars } from '../types'; import { UrlQueryMap, urlUtil } from './url'; -let grafanaConfig: GrafanaConfig = { appSubUrl: '' } as any; +let grafanaConfig = { appSubUrl: '' } as GrafanaConfig; let getTimeRangeUrlParams: () => RawTimeRange; let getVariablesUrlParams: (scopedVars?: ScopedVars) => UrlQueryMap; diff --git a/packages/grafana-data/src/utils/testdata/testTheme.ts b/packages/grafana-data/src/utils/testdata/testTheme.ts deleted file mode 100644 index cbb442c9e58..00000000000 --- a/packages/grafana-data/src/utils/testdata/testTheme.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { GrafanaTheme, GrafanaThemeType } from '../../types/theme'; - -export function getTestTheme(type: GrafanaThemeType = GrafanaThemeType.Dark): GrafanaTheme { - return { - type, - isDark: type === GrafanaThemeType.Dark, - isLight: type === GrafanaThemeType.Light, - colors: { - panelBg: 'white', - }, - } as unknown as GrafanaTheme; -} diff --git a/packages/grafana-data/src/utils/valueMappings.ts b/packages/grafana-data/src/utils/valueMappings.ts index 063e47d77a4..a0df9109dc6 100644 --- a/packages/grafana-data/src/utils/valueMappings.ts +++ b/packages/grafana-data/src/utils/valueMappings.ts @@ -76,13 +76,13 @@ export function getValueMappingResult(valueMappings: ValueMapping[], value: any) break; } case SpecialValueMatch.NaN: { - if (isNaN(value as any)) { + if (isNaN(value as number)) { return vm.options.result; } break; } case SpecialValueMatch.NullAndNaN: { - if (isNaN(value as any) || value == null) { + if (isNaN(value as number) || value == null) { return vm.options.result; } break; @@ -113,7 +113,7 @@ export function getValueMappingResult(valueMappings: ValueMapping[], value: any) } // Ref https://stackoverflow.com/a/58550111 -export function isNumeric(num: any) { +export function isNumeric(num: unknown) { return (typeof num === 'number' || (typeof num === 'string' && num.trim() !== '')) && !isNaN(num as number); } diff --git a/packages/grafana-data/src/vector/AsNumberVector.ts b/packages/grafana-data/src/vector/AsNumberVector.ts index ac8644442be..cc47ad3d7ec 100644 --- a/packages/grafana-data/src/vector/AsNumberVector.ts +++ b/packages/grafana-data/src/vector/AsNumberVector.ts @@ -9,6 +9,6 @@ import { Vector } from '../types'; export class AsNumberVector extends Array { constructor(field: Vector) { super(); - return field.map((v) => +v) as AsNumberVector; + return field.map((v) => +v); } } diff --git a/packages/grafana-data/src/vector/BinaryOperationVector.ts b/packages/grafana-data/src/vector/BinaryOperationVector.ts index 933d3dafe8a..4848e040e2f 100644 --- a/packages/grafana-data/src/vector/BinaryOperationVector.ts +++ b/packages/grafana-data/src/vector/BinaryOperationVector.ts @@ -13,6 +13,6 @@ export class BinaryOperationVector extends Array { for (let i = 0; i < arr.length; i++) { arr[i] = operation(left[i], right[i]); } - return arr as BinaryOperationVector; + return arr; } } diff --git a/packages/grafana-data/src/vector/ConstantVector.ts b/packages/grafana-data/src/vector/ConstantVector.ts index 65a96ec4143..0eb19fc7636 100644 --- a/packages/grafana-data/src/vector/ConstantVector.ts +++ b/packages/grafana-data/src/vector/ConstantVector.ts @@ -5,6 +5,6 @@ export class ConstantVector extends Array { constructor(value: T, len: number) { super(); - return new Array(len).fill(value) as ConstantVector; + return new Array(len).fill(value); } } diff --git a/packages/grafana-data/src/vector/FormattedVector.ts b/packages/grafana-data/src/vector/FormattedVector.ts index 6dfbf087f6d..8e4cd9be949 100644 --- a/packages/grafana-data/src/vector/FormattedVector.ts +++ b/packages/grafana-data/src/vector/FormattedVector.ts @@ -9,6 +9,6 @@ import { formattedValueToString } from '../valueFormats'; export class FormattedVector extends Array { constructor(source: Vector, formatter: DisplayProcessor) { super(); - return source.map((v) => formattedValueToString(formatter(v))) as FormattedVector; + return source.map((v) => formattedValueToString(formatter(v))); } } diff --git a/packages/grafana-data/src/vector/IndexVector.ts b/packages/grafana-data/src/vector/IndexVector.ts index c32eb98ca60..1dfeb92ab36 100644 --- a/packages/grafana-data/src/vector/IndexVector.ts +++ b/packages/grafana-data/src/vector/IndexVector.ts @@ -14,7 +14,7 @@ export class IndexVector extends Array { for (let i = 0; i < len; i++) { arr[i] = i; } - return arr as IndexVector; + return arr; } /** diff --git a/packages/grafana-runtime/src/services/backendSrv.ts b/packages/grafana-runtime/src/services/backendSrv.ts index 341794835b9..bb52f761e5b 100644 --- a/packages/grafana-runtime/src/services/backendSrv.ts +++ b/packages/grafana-runtime/src/services/backendSrv.ts @@ -147,10 +147,10 @@ export function isFetchError(e: unknown): e is FetchError { */ export interface BackendSrv { get(url: string, params?: any, requestId?: string, options?: Partial): Promise; - delete(url: string, data?: any, options?: Partial): Promise; - post(url: string, data?: any, options?: Partial): Promise; - patch(url: string, data?: any, options?: Partial): Promise; - put(url: string, data?: any, options?: Partial): Promise; + delete(url: string, data?: unknown, options?: Partial): Promise; + post(url: string, data?: unknown, options?: Partial): Promise; + patch(url: string, data?: unknown, options?: Partial): Promise; + put(url: string, data?: unknown, options?: Partial): Promise; /** * @deprecated Use the `.fetch()` function instead. If you prefer to work with a promise diff --git a/public/app/core/components/TagFilter/TagFilter.tsx b/public/app/core/components/TagFilter/TagFilter.tsx index e64d807e170..7d6a34ae325 100644 --- a/public/app/core/components/TagFilter/TagFilter.tsx +++ b/public/app/core/components/TagFilter/TagFilter.tsx @@ -143,7 +143,7 @@ export const TagFilter = ({ width, components: { Option: TagOption, - MultiValueLabel: (): any => { + MultiValueLabel: () => { return null; // We want the whole tag to be clickable so we use MultiValueRemove instead }, MultiValueRemove(props: any) { @@ -155,7 +155,7 @@ export const TagFilter = ({ ); }, - MultiValueContainer: hideValues ? (): any => null : components.MultiValueContainer, + MultiValueContainer: hideValues ? () => null : components.MultiValueContainer, }, }; diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 2d4245b72eb..1dac7e529fa 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -416,7 +416,7 @@ export class BackendSrv implements BackendService { ); } - private handleStreamCancellation(options: BackendSrvRequest): MonoTypeOperatorFunction> { + private handleStreamCancellation(options: BackendSrvRequest): MonoTypeOperatorFunction { return (inputStream) => inputStream.pipe( takeUntil( @@ -452,7 +452,7 @@ export class BackendSrv implements BackendService { ); } - getInspectorStream(): Observable | FetchError> { + getInspectorStream(): Observable { return this.inspectorStream; } @@ -465,23 +465,23 @@ export class BackendSrv implements BackendService { return this.request({ ...options, method: 'GET', url, params, requestId }); } - async delete(url: string, data?: any, options?: Partial) { + async delete(url: string, data?: unknown, options?: Partial) { return this.request({ ...options, method: 'DELETE', url, data }); } - async post(url: string, data?: any, options?: Partial) { + async post(url: string, data?: unknown, options?: Partial) { return this.request({ ...options, method: 'POST', url, data }); } - async patch(url: string, data: any, options?: Partial) { + async patch(url: string, data: unknown, options?: Partial) { return this.request({ ...options, method: 'PATCH', url, data }); } - async put(url: string, data: any, options?: Partial): Promise { + async put(url: string, data: unknown, options?: Partial): Promise { return this.request({ ...options, method: 'PUT', url, data }); } - withNoBackendCache(callback: any) { + withNoBackendCache(callback: () => Promise) { this.noBackendCache = true; return callback().finally(() => { this.noBackendCache = false; diff --git a/public/app/core/specs/time_series.test.ts b/public/app/core/specs/time_series.test.ts index 933759cb17e..df77e673128 100644 --- a/public/app/core/specs/time_series.test.ts +++ b/public/app/core/specs/time_series.test.ts @@ -1,9 +1,9 @@ import TimeSeries, { updateLegendValues } from 'app/core/time_series2'; describe('TimeSeries', () => { - let points: any[][]; + let points: ReturnType; let series: TimeSeries; - let testData: { alias?: string; datapoints: any }; + let testData: { alias?: string; datapoints: Array<[number | null, number | null]> }; beforeEach(() => { testData = { diff --git a/public/app/core/utils/query.ts b/public/app/core/utils/query.ts index 11fca8e6898..bd5cdefe808 100644 --- a/public/app/core/utils/query.ts +++ b/public/app/core/utils/query.ts @@ -27,15 +27,17 @@ export function queryIsEmpty(query: DataQuery): boolean { } export function addQuery(queries: DataQuery[], query?: Partial, datasource?: DataSourceRef): DataQuery[] { - const q = query || {}; - q.refId = getNextRefIdChar(queries); - q.hide = false; + const q: DataQuery = { + ...query, + refId: getNextRefIdChar(queries), + hide: false, + }; if (!q.datasource && datasource) { q.datasource = datasource; } - return [...queries, q as DataQuery]; + return [...queries, q]; } export function isDataQuery(url: string): boolean { diff --git a/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx b/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx index 9620dbf93da..8d33c54e6a8 100644 --- a/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx +++ b/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx @@ -184,11 +184,8 @@ describe('PanelAlertTabContent', () => { const dsService = new MockDataSourceSrv(dataSources); dsService.datasources[dataSources.prometheus.uid] = new PrometheusDatasource( dataSources.prometheus - ) as DataSourceApi; - dsService.datasources[dataSources.default.uid] = new PrometheusDatasource(dataSources.default) as DataSourceApi< - any, - any - >; + ) as DataSourceApi; + dsService.datasources[dataSources.default.uid] = new PrometheusDatasource(dataSources.default) as DataSourceApi; setDataSourceSrv(dsService); disableRBAC(); }); diff --git a/public/app/features/alerting/unified/components/Expression.tsx b/public/app/features/alerting/unified/components/Expression.tsx index 601ed4dbfb3..dce352a0f92 100644 --- a/public/app/features/alerting/unified/components/Expression.tsx +++ b/public/app/features/alerting/unified/components/Expression.tsx @@ -1,5 +1,5 @@ import { css, cx } from '@emotion/css'; -import { LanguageMap, languages as prismLanguages } from 'prismjs'; +import { languages as prismLanguages } from 'prismjs'; import React, { FC, useMemo } from 'react'; import { Editor } from 'slate-react'; @@ -23,10 +23,10 @@ export const HighlightedQuery: FC<{ language: 'promql' | 'logql'; expr: string } () => [ SlatePrism( { - onlyIn: (node: any) => node.type === 'code_block', + onlyIn: (node) => 'type' in node && node.type === 'code_block', getSyntax: () => language, }, - { ...(prismLanguages as LanguageMap), [language]: language === 'logql' ? LogqlSyntax : PromqlSyntax } + { ...prismLanguages, [language]: language === 'logql' ? LogqlSyntax : PromqlSyntax } ), ], [language] diff --git a/public/app/features/alerting/unified/components/receivers/TemplateForm.tsx b/public/app/features/alerting/unified/components/receivers/TemplateForm.tsx index 46f6ea49db8..c498d25bd2b 100644 --- a/public/app/features/alerting/unified/components/receivers/TemplateForm.tsx +++ b/public/app/features/alerting/unified/components/receivers/TemplateForm.tsx @@ -8,6 +8,7 @@ import AutoSizer from 'react-virtualized-auto-sizer'; import { GrafanaTheme2 } from '@grafana/data'; import { Stack } from '@grafana/experimental'; +import { isFetchError } from '@grafana/runtime'; import { Alert, Button, @@ -159,7 +160,7 @@ export const TemplateForm = ({ existing, alertManagerSourceName, config, provena

{existing && !isduplicating ? 'Edit notification template' : 'Create notification template'}

{error && ( - {error.message || (error as any)?.data?.message || String(error)} + {error.message || (isFetchError(error) && error.data?.message) || String(error)} )} {provenance && } diff --git a/public/app/features/alerting/unified/components/receivers/form/TestContactPointModal.tsx b/public/app/features/alerting/unified/components/receivers/form/TestContactPointModal.tsx index 16658740d6c..d951f444285 100644 --- a/public/app/features/alerting/unified/components/receivers/form/TestContactPointModal.tsx +++ b/public/app/features/alerting/unified/components/receivers/form/TestContactPointModal.tsx @@ -49,14 +49,14 @@ export const TestContactPointModal = ({ isOpen, onDismiss, onTest }: Props) => { const alert = { annotations: data.annotations .filter(({ key, value }) => !!key && !!value) - .reduce((acc, { key, value }) => { + .reduce((acc, { key, value }) => { return { ...acc, [key]: value }; - }, {} as Annotations), + }, {}), labels: data.labels .filter(({ key, value }) => !!key && !!value) - .reduce((acc, { key, value }) => { + .reduce((acc, { key, value }) => { return { ...acc, [key]: value }; - }, {} as Labels), + }, {}), }; onTest(alert); } else { diff --git a/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx b/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx index 5c94362453e..1c9969cc672 100644 --- a/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx @@ -112,7 +112,7 @@ export const AlertRuleForm = ({ existing, prefill }: Props) => { const ruleType = translateRouteParamToRuleType(routeParams.type); const uidFromParams = routeParams.id; - const returnTo: string = (queryParams['returnTo'] as string | undefined) ?? '/alerting/list'; + const returnTo = String(queryParams['returnTo']) ?? '/alerting/list'; const [showDeleteModal, setShowDeleteModal] = useState(false); const defaultValues: RuleFormValues = useMemo(() => { diff --git a/public/app/features/alerting/unified/components/rules/RuleDetailsDataSources.tsx b/public/app/features/alerting/unified/components/rules/RuleDetailsDataSources.tsx index c3cfa95dfa3..8f5b3028e80 100644 --- a/public/app/features/alerting/unified/components/rules/RuleDetailsDataSources.tsx +++ b/public/app/features/alerting/unified/components/rules/RuleDetailsDataSources.tsx @@ -27,19 +27,16 @@ export function RuleDetailsDataSources(props: Props): JSX.Element | null { if (isGrafanaRulerRule(rule.rulerRule)) { const { data } = rule.rulerRule.grafana_alert; - const unique = data.reduce( - (dataSources, query) => { - const ds = getDataSourceSrv().getInstanceSettings(query.datasourceUid); + const unique = data.reduce>((dataSources, query) => { + const ds = getDataSourceSrv().getInstanceSettings(query.datasourceUid); - if (!ds || ds.uid === ExpressionDatasourceUID) { - return dataSources; - } - - dataSources[ds.name] = { name: ds.name, icon: ds.meta.info.logos.small }; + if (!ds || ds.uid === ExpressionDatasourceUID) { return dataSources; - }, - {} as Record - ); + } + + dataSources[ds.name] = { name: ds.name, icon: ds.meta.info.logos.small }; + return dataSources; + }, {}); return Object.values(unique); } diff --git a/public/app/features/alerting/unified/hooks/useFilteredRules.ts b/public/app/features/alerting/unified/hooks/useFilteredRules.ts index c336d065fc6..2d98221faf9 100644 --- a/public/app/features/alerting/unified/hooks/useFilteredRules.ts +++ b/public/app/features/alerting/unified/hooks/useFilteredRules.ts @@ -136,7 +136,7 @@ export const filterRules = ( } // If a namespace and group have rules that match the rules filters then keep them. - return filteredNamespaces.reduce(reduceNamespaces(filterState), [] as CombinedRuleNamespace[]); + return filteredNamespaces.reduce(reduceNamespaces(filterState), []); }; const reduceNamespaces = (filterState: RulesFilter) => { @@ -154,7 +154,7 @@ const reduceNamespaces = (filterState: RulesFilter) => { } } - filteredGroups = filteredGroups.reduce(reduceGroups(filterState), [] as CombinedRuleGroup[]); + filteredGroups = filteredGroups.reduce(reduceGroups(filterState), []); if (filteredGroups.length) { namespaceAcc.push({ diff --git a/public/app/features/alerting/unified/hooks/useGroupedAlerts.ts b/public/app/features/alerting/unified/hooks/useGroupedAlerts.ts index 1390f21b523..4a0897e45ce 100644 --- a/public/app/features/alerting/unified/hooks/useGroupedAlerts.ts +++ b/public/app/features/alerting/unified/hooks/useGroupedAlerts.ts @@ -10,7 +10,7 @@ export const useGroupedAlerts = (groups: AlertmanagerGroup[], groupBy: string[]) const emptyGroupings = groups.filter((group) => Object.keys(group.labels).length === 0); if (emptyGroupings.length > 1) { // Merges multiple ungrouped grouping - return groups.reduce((combinedGroups, group) => { + return groups.reduce((combinedGroups, group) => { if (Object.keys(group.labels).length === 0) { const noGroupingGroup = combinedGroups.find(({ labels }) => Object.keys(labels)); if (!noGroupingGroup) { @@ -22,13 +22,13 @@ export const useGroupedAlerts = (groups: AlertmanagerGroup[], groupBy: string[]) combinedGroups.push(group); } return combinedGroups; - }, [] as AlertmanagerGroup[]); + }, []); } else { return groups; } } const alerts = groups.flatMap(({ alerts }) => alerts); - return alerts.reduce((groupings, alert) => { + return alerts.reduce((groupings, alert) => { const alertContainsGroupings = groupBy.every((groupByLabel) => Object.keys(alert.labels).includes(groupByLabel)); if (alertContainsGroupings) { @@ -38,10 +38,10 @@ export const useGroupedAlerts = (groups: AlertmanagerGroup[], groupBy: string[]) }); }); if (!existingGrouping) { - const labels = groupBy.reduce((acc, key) => { + const labels = groupBy.reduce((acc, key) => { acc = { ...acc, [key]: alert.labels[key] }; return acc; - }, {} as Labels); + }, {}); groupings.push({ alerts: [alert], labels, @@ -62,6 +62,6 @@ export const useGroupedAlerts = (groups: AlertmanagerGroup[], groupBy: string[]) } return groupings; - }, [] as AlertmanagerGroup[]); + }, []); }, [groups, groupBy]); }; diff --git a/public/app/features/alerting/unified/utils/amroutes.ts b/public/app/features/alerting/unified/utils/amroutes.ts index f56baec8aa9..fdbb13b0c8e 100644 --- a/public/app/features/alerting/unified/utils/amroutes.ts +++ b/public/app/features/alerting/unified/utils/amroutes.ts @@ -25,7 +25,7 @@ const matchersToArrayFieldMatchers = ( operator: isRegex ? MatcherOperator.regex : MatcherOperator.equal, }, ], - [] as MatcherFieldValue[] + [] ); const selectableValueToString = (selectableValue: SelectableValue): string => selectableValue.value!; @@ -149,9 +149,9 @@ export const formAmRouteToAmRoute = ( const overrideRepeatInterval = overrideTimings && repeatIntervalValue; const repeat_interval = overrideRepeatInterval ? repeatIntervalValue : INHERIT_FROM_PARENT; - const object_matchers = formAmRoute.object_matchers + const object_matchers: ObjectMatcher[] | undefined = formAmRoute.object_matchers ?.filter((route) => route.name && route.value && route.operator) - .map(({ name, operator, value }) => [name, operator, value] as ObjectMatcher); + .map(({ name, operator, value }) => [name, operator, value]); const routes = formAmRoute.routes?.map((subRoute) => formAmRouteToAmRoute(alertManagerSourceName, subRoute, routeTree) diff --git a/public/app/features/alerting/unified/utils/receiver-form.ts b/public/app/features/alerting/unified/utils/receiver-form.ts index 829e351d287..d779c9f2cb8 100644 --- a/public/app/features/alerting/unified/utils/receiver-form.ts +++ b/public/app/features/alerting/unified/utils/receiver-form.ts @@ -54,7 +54,7 @@ export function cloudReceiverToFormValues( // map property names to cloud notifier types by removing the `_config` suffix .map(([type, configs]): [CloudNotifierType, CloudChannelConfig[]] => [ type.replace('_configs', '') as CloudNotifierType, - configs as CloudChannelConfig[], + configs, ]) // convert channel configs to form values .map(([type, configs]) => @@ -115,7 +115,7 @@ export function formValuesToCloudReceiver( if (!(`${type}_configs` in recv)) { recv[`${type}_configs`] = [channel]; } else { - (recv[`${type}_configs`] as unknown[]).push(channel); + recv[`${type}_configs`]?.push(channel); } }); return recv; diff --git a/public/app/features/alerting/unified/utils/rules.ts b/public/app/features/alerting/unified/utils/rules.ts index 1a94e098e7c..03dd44878ff 100644 --- a/public/app/features/alerting/unified/utils/rules.ts +++ b/public/app/features/alerting/unified/utils/rules.ts @@ -169,20 +169,17 @@ export function getFirstActiveAt(promRule?: AlertingRule) { if (!promRule?.alerts) { return null; } - return promRule.alerts.reduce( - (prev, alert) => { - const isNotNormal = - mapStateWithReasonToBaseState(alert.state as GrafanaAlertStateWithReason) !== GrafanaAlertState.Normal; - if (alert.activeAt && isNotNormal) { - const activeAt = new Date(alert.activeAt); - if (prev === null || prev.getTime() > activeAt.getTime()) { - return activeAt; - } + return promRule.alerts.reduce((prev, alert) => { + const isNotNormal = + mapStateWithReasonToBaseState(alert.state as GrafanaAlertStateWithReason) !== GrafanaAlertState.Normal; + if (alert.activeAt && isNotNormal) { + const activeAt = new Date(alert.activeAt); + if (prev === null || prev.getTime() > activeAt.getTime()) { + return activeAt; } - return prev; - }, - null as Date | null - ); + } + return prev; + }, null); } /** diff --git a/public/app/features/canvas/runtime/element.tsx b/public/app/features/canvas/runtime/element.tsx index 19d3d1af267..5062d017edd 100644 --- a/public/app/features/canvas/runtime/element.tsx +++ b/public/app/features/canvas/runtime/element.tsx @@ -86,7 +86,7 @@ export class ElementState implements LayerElement { const { constraint } = this.options; const { vertical, horizontal } = constraint ?? {}; - const placement = this.options.placement ?? ({} as Placement); + const placement: Placement = this.options.placement ?? {}; const editingEnabled = this.getScene()?.isEditingEnabled; @@ -229,7 +229,7 @@ export class ElementState implements LayerElement { ? Math.round(parentContainer.right - parentBorderWidth - elementContainer.right) : 0; - const placement = {} as Placement; + const placement: Placement = {}; const width = elementContainer?.width ?? 100; const height = elementContainer?.height ?? 100; diff --git a/public/app/features/canvas/runtime/frame.tsx b/public/app/features/canvas/runtime/frame.tsx index 0d8ef5ee588..96516129c05 100644 --- a/public/app/features/canvas/runtime/frame.tsx +++ b/public/app/features/canvas/runtime/frame.tsx @@ -134,7 +134,7 @@ export class FrameState extends ElementState { if (shiftItemsOnDuplicate) { const { constraint, placement: oldPlacement } = element.options; const { vertical, horizontal } = constraint ?? {}; - const placement = { ...oldPlacement } ?? ({} as Placement); + const placement: Placement = { ...oldPlacement } ?? {}; switch (vertical) { case VerticalConstraint.Top: diff --git a/public/app/features/dashboard-scene/utils/test-utils.ts b/public/app/features/dashboard-scene/utils/test-utils.ts index 4a727f13141..9c0ac06f638 100644 --- a/public/app/features/dashboard-scene/utils/test-utils.ts +++ b/public/app/features/dashboard-scene/utils/test-utils.ts @@ -11,7 +11,7 @@ export function setupLoadDashboardMock(rsp: DeepPartial) { } export function mockResizeObserver() { - (window as any).ResizeObserver = class ResizeObserver { + window.ResizeObserver = class ResizeObserver { constructor(callback: ResizeObserverCallback) { setTimeout(() => { callback( diff --git a/public/app/features/dashboard/components/VersionHistory/utils.ts b/public/app/features/dashboard/components/VersionHistory/utils.ts index 3733926c3eb..84c6fc9aa5d 100644 --- a/public/app/features/dashboard/components/VersionHistory/utils.ts +++ b/public/app/features/dashboard/components/VersionHistory/utils.ts @@ -5,8 +5,8 @@ import { flow, get, isArray, isEmpty, last, sortBy, tail, toNumber, isNaN } from export type Diff = { op: 'add' | 'replace' | 'remove' | 'copy' | 'test' | '_get' | 'move'; - value: any; - originalValue: any; + value: unknown; + originalValue: unknown; path: string[]; startLineNumber: number; }; diff --git a/public/app/features/dashboard/utils/panelMerge.ts b/public/app/features/dashboard/utils/panelMerge.ts index 3e777c73d26..309b7fddea7 100644 --- a/public/app/features/dashboard/utils/panelMerge.ts +++ b/public/app/features/dashboard/utils/panelMerge.ts @@ -43,7 +43,7 @@ export function mergePanels(current: PanelModel[], data: IPanelModel[]): PanelMe } for (const panel of current) { - const target = inputPanels.get(panel.id) as PanelModel; + const target = inputPanels.get(panel.id); if (!target) { info.changed = true; info.actions.remove.push(panel.id); diff --git a/public/app/features/query/state/DashboardQueryRunner/SnapshotWorker.ts b/public/app/features/query/state/DashboardQueryRunner/SnapshotWorker.ts index 861b1cbd819..43f187c2cff 100644 --- a/public/app/features/query/state/DashboardQueryRunner/SnapshotWorker.ts +++ b/public/app/features/query/state/DashboardQueryRunner/SnapshotWorker.ts @@ -24,9 +24,9 @@ export class SnapshotWorker implements DashboardQueryRunnerWorker { private getAnnotationsFromSnapshot(dashboard: DashboardModel): AnnotationEvent[] { const dashAnnotations = dashboard?.annotations?.list?.filter((a) => a.enable); const snapshots = dashAnnotations.filter((a) => Boolean(a.snapshotData)); - const annotations = snapshots.reduce( + const annotations = snapshots.reduce( (acc, curr) => acc.concat(translateQueryResult(curr, curr.snapshotData)), - [] as AnnotationEvent[] + [] ); return annotations; diff --git a/public/app/features/variables/inspect/utils.ts b/public/app/features/variables/inspect/utils.ts index f123858d113..16e1f3cf88d 100644 --- a/public/app/features/variables/inspect/utils.ts +++ b/public/app/features/variables/inspect/utils.ts @@ -118,58 +118,52 @@ const validVariableNames: Record = { }; export const getPropsWithVariable = (variableId: string, parent: { key: string; value: any }, result: any) => { - const stringValues = Object.keys(parent.value).reduce( - (all, key) => { - const value = parent.value[key]; - if (!value || typeof value !== 'string') { - return all; - } + const stringValues = Object.keys(parent.value).reduce>((all, key) => { + const value = parent.value[key]; + if (!value || typeof value !== 'string') { + return all; + } + + const isValidName = validVariableNames[key] + ? validVariableNames[key].find((regex: RegExp) => regex.test(variableId)) + : undefined; + + let hasVariable = containsVariable(value, variableId); + if (key === 'repeat' && value === variableId) { + // repeat stores value without variable format + hasVariable = true; + } + + if (!isValidName && hasVariable) { + all = { + ...all, + [key]: value, + }; + } - const isValidName = validVariableNames[key] - ? validVariableNames[key].find((regex: RegExp) => regex.test(variableId)) - : undefined; + return all; + }, {}); - let hasVariable = containsVariable(value, variableId); - if (key === 'repeat' && value === variableId) { - // repeat stores value without variable format - hasVariable = true; + const objectValues = Object.keys(parent.value).reduce>((all, key) => { + const value = parent.value[key]; + if (value && typeof value === 'object' && Object.keys(value).length) { + let id = value.title || value.name || value.id || key; + if (Array.isArray(parent.value) && parent.key === 'panels') { + id = `${id}[${value.id}]`; } - if (!isValidName && hasVariable) { + const newResult = getPropsWithVariable(variableId, { key, value }, {}); + + if (Object.keys(newResult).length) { all = { ...all, - [key]: value, + [id]: newResult, }; } + } - return all; - }, - {} as Record - ); - - const objectValues = Object.keys(parent.value).reduce( - (all, key) => { - const value = parent.value[key]; - if (value && typeof value === 'object' && Object.keys(value).length) { - let id = value.title || value.name || value.id || key; - if (Array.isArray(parent.value) && parent.key === 'panels') { - id = `${id}[${value.id}]`; - } - - const newResult = getPropsWithVariable(variableId, { key, value }, {}); - - if (Object.keys(newResult).length) { - all = { - ...all, - [id]: newResult, - }; - } - } - - return all; - }, - {} as Record - ); + return all; + }, {}); if (Object.keys(stringValues).length || Object.keys(objectValues).length) { result = { @@ -341,7 +335,7 @@ export const transformUsagesToNetwork = (usages: VariableUsageTree[]): UsagesToN return results; }; -const countLeaves = (object: any): number => { +const countLeaves = (object: object): number => { const total = Object.values(object).reduce((count: number, value: any) => { if (typeof value === 'object') { return count + countLeaves(value); @@ -350,7 +344,7 @@ const countLeaves = (object: any): number => { return count + 1; }, 0); - return total as unknown as number; + return total; }; export const getVariableUsages = (variableId: string, usages: VariableUsageTree[]): number => { diff --git a/public/app/features/variables/pickers/OptionsPicker/reducer.test.ts b/public/app/features/variables/pickers/OptionsPicker/reducer.test.ts index 9838ba4714e..2fba9f320e6 100644 --- a/public/app/features/variables/pickers/OptionsPicker/reducer.test.ts +++ b/public/app/features/variables/pickers/OptionsPicker/reducer.test.ts @@ -65,7 +65,7 @@ describe('optionsPickerReducer', () => { clearOthers: args.clearOthers, option: { text: args.option, value: args.option, selected: true }, }; - const expectedAsRecord: any = args.expectSelected.reduce((all: any, current: any) => { + const expectedAsRecord = args.expectSelected.reduce((all: any, current: any) => { all[current] = current; return all; }, {}); diff --git a/public/app/features/variables/query/actions.ts b/public/app/features/variables/query/actions.ts index 41b3131846e..a81391dca21 100644 --- a/public/app/features/variables/query/actions.ts +++ b/public/app/features/variables/query/actions.ts @@ -184,25 +184,22 @@ export function flattenQuery(query: any): any { } const keys = Object.keys(query); - const flattened = keys.reduce( - (all, key) => { - const value = query[key]; - if (typeof value !== 'object' || value === null) { - all[key] = value; - return all; - } + const flattened = keys.reduce>((all, key) => { + const value = query[key]; + if (typeof value !== 'object' || value === null) { + all[key] = value; + return all; + } - const result = flattenQuery(value); - for (let childProp in result) { - if (result.hasOwnProperty(childProp)) { - all[`${key}_${childProp}`] = result[childProp]; - } + const result = flattenQuery(value); + for (let childProp in result) { + if (result.hasOwnProperty(childProp)) { + all[`${key}_${childProp}`] = result[childProp]; } + } - return all; - }, - {} as Record - ); + return all; + }, {}); return flattened; } diff --git a/public/app/features/variables/state/actions.ts b/public/app/features/variables/state/actions.ts index 631450e8571..0ac422a8725 100644 --- a/public/app/features/variables/state/actions.ts +++ b/public/app/features/variables/state/actions.ts @@ -877,10 +877,10 @@ const getQueryWithVariables = (key: string, getState: () => StoreState): UrlQuer const queryParamsNew = Object.keys(queryParams) .filter((key) => key.indexOf(VARIABLE_PREFIX) === -1) - .reduce((obj, key) => { + .reduce((obj, key) => { obj[key] = queryParams[key]; return obj; - }, {} as UrlQueryMap); + }, {}); for (const variable of getVariablesByKey(key, getState())) { if (variable.skipUrlSync) { diff --git a/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx b/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx index 045fdefc119..f011d01a1b7 100644 --- a/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx +++ b/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx @@ -100,8 +100,8 @@ class PromQueryField extends React.PureComponent node.type === 'code_block', - getSyntax: (node: any) => 'promql', + onlyIn: (node) => 'type' in node && node.type === 'code_block', + getSyntax: (node) => 'promql', }, { ...(prismLanguages as LanguageMap), promql: this.props.datasource.languageProvider.syntax } ), diff --git a/public/app/plugins/datasource/prometheus/querybuilder/binaryScalarOperations.ts b/public/app/plugins/datasource/prometheus/querybuilder/binaryScalarOperations.ts index 69e3c2654b1..9c175126e10 100644 --- a/public/app/plugins/datasource/prometheus/querybuilder/binaryScalarOperations.ts +++ b/public/app/plugins/datasource/prometheus/querybuilder/binaryScalarOperations.ts @@ -71,16 +71,15 @@ export const binaryScalarDefs = [ }, ]; -export const binaryScalarOperatorToOperatorName = binaryScalarDefs.reduce( - (acc, def) => { - acc[def.sign] = { - id: def.id, - comparison: def.comparison, - }; - return acc; - }, - {} as Record -); +export const binaryScalarOperatorToOperatorName = binaryScalarDefs.reduce< + Record +>((acc, def) => { + acc[def.sign] = { + id: def.id, + comparison: def.comparison, + }; + return acc; +}, {}); // Not sure about this one. It could also be a more generic 'Simple math operation' where user specifies // both the operator and the operand in a single input diff --git a/public/app/plugins/datasource/tempo/testResponse.ts b/public/app/plugins/datasource/tempo/testResponse.ts index b9e442fe34d..69109410823 100644 --- a/public/app/plugins/datasource/tempo/testResponse.ts +++ b/public/app/plugins/datasource/tempo/testResponse.ts @@ -1,4 +1,4 @@ -import { MutableDataFrame } from '@grafana/data'; +import { FieldType, MutableDataFrame } from '@grafana/data'; export const bigResponse = new MutableDataFrame({ fields: [ @@ -1807,73 +1807,73 @@ export const otlpDataFrameFromResponse = new MutableDataFrame({ fields: [ { name: 'traceID', - type: 'string', + type: FieldType.string, config: {}, values: ['60ba2abb44f13eae'], }, { name: 'spanID', - type: 'string', + type: FieldType.string, config: {}, values: ['726b5e30102fc0d0'], }, { name: 'parentSpanID', - type: 'string', + type: FieldType.string, config: {}, values: ['398f0f21a3db99ae'], }, { name: 'operationName', - type: 'string', + type: FieldType.string, config: {}, values: ['HTTP GET - root'], }, { name: 'serviceName', - type: 'string', + type: FieldType.string, config: {}, values: ['db'], }, { name: 'kind', - type: 'string', + type: FieldType.string, config: {}, values: ['client'], }, { name: 'statusCode', - type: 'number', + type: FieldType.number, config: {}, values: [2], }, { name: 'statusMessage', - type: 'string', + type: FieldType.string, config: {}, values: ['message'], }, { name: 'instrumentationLibraryName', - type: 'string', + type: FieldType.string, config: {}, values: ['libraryName'], }, { name: 'instrumentationLibraryVersion', - type: 'string', + type: FieldType.string, config: {}, values: ['libraryVersion'], }, { name: 'traceState', - type: 'string', + type: FieldType.string, config: {}, values: ['traceState'], }, { name: 'serviceTags', - type: 'other', + type: FieldType.other, config: {}, values: [ [ @@ -1906,25 +1906,25 @@ export const otlpDataFrameFromResponse = new MutableDataFrame({ }, { name: 'startTime', - type: 'number', + type: FieldType.number, config: {}, values: [1627471657255.809], }, { name: 'duration', - type: 'number', + type: FieldType.number, config: {}, values: [0.459008], }, { name: 'logs', - type: 'other', + type: FieldType.other, config: {}, values: [[]], }, { name: 'references', - type: 'other', + type: FieldType.other, config: {}, values: [ [ @@ -1946,7 +1946,7 @@ export const otlpDataFrameFromResponse = new MutableDataFrame({ }, { name: 'tags', - type: 'other', + type: FieldType.other, config: {}, values: [ [ @@ -1971,7 +1971,7 @@ export const otlpDataFrameFromResponse = new MutableDataFrame({ }, ], length: 1, -} as any); +}); export const otlpDataFrameToResponse = new MutableDataFrame({ meta: { @@ -1983,7 +1983,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ fields: [ { name: 'traceID', - type: 'string', + type: FieldType.string, config: {}, values: ['60ba2abb44f13eae'], state: { @@ -1992,7 +1992,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'spanID', - type: 'string', + type: FieldType.string, config: {}, values: ['726b5e30102fc0d0'], state: { @@ -2001,7 +2001,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'parentSpanID', - type: 'string', + type: FieldType.string, config: {}, values: ['398f0f21a3db99ae'], state: { @@ -2010,7 +2010,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'operationName', - type: 'string', + type: FieldType.string, config: {}, values: ['HTTP GET - root'], state: { @@ -2019,7 +2019,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'serviceName', - type: 'string', + type: FieldType.string, config: {}, values: ['db'], state: { @@ -2028,7 +2028,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'kind', - type: 'string', + type: FieldType.string, config: {}, values: ['client'], state: { @@ -2037,7 +2037,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'statusCode', - type: 'number', + type: FieldType.number, config: {}, values: [2], state: { @@ -2046,7 +2046,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'statusMessage', - type: 'string', + type: FieldType.string, config: {}, values: ['message'], state: { @@ -2055,7 +2055,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'instrumentationLibraryName', - type: 'string', + type: FieldType.string, config: {}, values: ['libraryName'], state: { @@ -2064,7 +2064,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'instrumentationLibraryVersion', - type: 'string', + type: FieldType.string, config: {}, values: ['libraryVersion'], state: { @@ -2073,7 +2073,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'traceState', - type: 'string', + type: FieldType.string, config: {}, values: ['traceState'], state: { @@ -2082,7 +2082,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'serviceTags', - type: 'other', + type: FieldType.other, config: {}, values: [ [ @@ -2118,7 +2118,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'startTime', - type: 'number', + type: FieldType.number, config: {}, values: [1627471657255.809], state: { @@ -2127,7 +2127,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'duration', - type: 'number', + type: FieldType.number, config: {}, values: [0.459008], state: { @@ -2136,7 +2136,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'logs', - type: 'other', + type: FieldType.other, config: {}, values: [[]], state: { @@ -2145,7 +2145,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'tags', - type: 'other', + type: FieldType.other, config: {}, values: [ [ @@ -2173,7 +2173,7 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, { name: 'references', - type: 'other', + type: FieldType.other, config: {}, labels: undefined, values: [ @@ -2198,9 +2198,8 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ }, }, ], - first: ['60ba2abb44f13eae'], length: 1, -} as any); +}); export const otlpResponse = { batches: [ diff --git a/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx b/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx index 65eaef3992c..1a3bf4dce7f 100644 --- a/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx +++ b/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx @@ -1,5 +1,4 @@ import { css } from '@emotion/css'; -import type { languages } from 'monaco-editor'; import React, { useEffect, useRef } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; @@ -194,8 +193,8 @@ function ensureTraceQL(monaco: Monaco) { traceqlSetupDone = true; const { aliases, extensions, mimetypes, def } = languageDefinition; monaco.languages.register({ id: langId, aliases, extensions, mimetypes }); - monaco.languages.setMonarchTokensProvider(langId, def.language as languages.IMonarchLanguage); - monaco.languages.setLanguageConfiguration(langId, def.languageConfiguration as languages.LanguageConfiguration); + monaco.languages.setMonarchTokensProvider(langId, def.language); + monaco.languages.setLanguageConfiguration(langId, def.languageConfiguration); } } diff --git a/public/app/plugins/datasource/tempo/traceql/traceql.ts b/public/app/plugins/datasource/tempo/traceql/traceql.ts index 0ee885433a7..adf40b6978b 100644 --- a/public/app/plugins/datasource/tempo/traceql/traceql.ts +++ b/public/app/plugins/datasource/tempo/traceql/traceql.ts @@ -1,6 +1,7 @@ +import type { languages } from 'monaco-editor'; import { Grammar } from 'prismjs'; -export const languageConfiguration = { +export const languageConfiguration: languages.LanguageConfiguration = { // the default separators except `@$` wordPattern: /(-?\d*\.\d\w*)|([^`~!#%^&*()\-=+\[{\]}\\|;:'",.<>\/?\s]+)/g, brackets: [ @@ -35,7 +36,7 @@ const keywords = intrinsics.concat(scopes); const statusValues = ['ok', 'unset', 'error', 'false', 'true']; -export const language = { +export const language: languages.IMonarchLanguage = { ignoreCase: false, defaultToken: '', tokenPostfix: '.traceql', diff --git a/public/app/plugins/datasource/testdata/components/StreamingClientEditor.tsx b/public/app/plugins/datasource/testdata/components/StreamingClientEditor.tsx index 1520e494d36..8297727f4f6 100644 --- a/public/app/plugins/datasource/testdata/components/StreamingClientEditor.tsx +++ b/public/app/plugins/datasource/testdata/components/StreamingClientEditor.tsx @@ -4,14 +4,13 @@ import { SelectableValue } from '@grafana/data'; import { InlineField, InlineFieldRow, Input, Select } from '@grafana/ui'; import { EditorProps } from '../QueryEditor'; -import { StreamingQuery } from '../dataquery.gen'; const streamingClientFields = [ { label: 'Speed (ms)', id: 'speed', placeholder: 'value', min: 10, step: 10 }, { label: 'Spread', id: 'spread', placeholder: 'value', min: 0.5, step: 0.1 }, { label: 'Noise', id: 'noise', placeholder: 'value', min: 0, step: 0.1 }, { label: 'Bands', id: 'bands', placeholder: 'bands', min: 0, step: 1 }, -]; +] as const; const types = [ { value: 'signal', label: 'Signal' }, @@ -46,7 +45,7 @@ export const StreamingClientEditor = ({ onChange, query }: EditorProps) => { name={id} min={min} step={step} - value={query.stream?.[id as keyof StreamingQuery]} + value={query.stream?.[id]} placeholder={placeholder} onChange={onInputChange} /> diff --git a/public/app/plugins/datasource/testdata/testData/serviceMapResponse.ts b/public/app/plugins/datasource/testdata/testData/serviceMapResponse.ts index c555674a9fd..dabecebcfc4 100644 --- a/public/app/plugins/datasource/testdata/testData/serviceMapResponse.ts +++ b/public/app/plugins/datasource/testdata/testData/serviceMapResponse.ts @@ -1,4 +1,4 @@ -import { FieldColorModeId, FieldType, PreferredVisualisationType, NodeGraphDataFrameFieldNames } from '@grafana/data'; +import { FieldColorModeId, FieldType, NodeGraphDataFrameFieldNames } from '@grafana/data'; export const nodes = { fields: [ @@ -157,7 +157,7 @@ export const nodes = { values: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], }, ], - meta: { preferredVisualisationType: 'nodeGraph' as PreferredVisualisationType }, + meta: { preferredVisualisationType: 'nodeGraph' as const }, name: 'nodes', }; @@ -333,6 +333,6 @@ export const edges = { ], }, ], - meta: { preferredVisualisationType: 'nodeGraph' as PreferredVisualisationType }, + meta: { preferredVisualisationType: 'nodeGraph' as const }, name: 'edges', }; diff --git a/public/app/plugins/panel/candlestick/CandlestickPanel.tsx b/public/app/plugins/panel/candlestick/CandlestickPanel.tsx index 0a78079f6f4..2611c40d823 100644 --- a/public/app/plugins/panel/candlestick/CandlestickPanel.tsx +++ b/public/app/plugins/panel/candlestick/CandlestickPanel.tsx @@ -110,12 +110,12 @@ export const CandlestickPanel = ({ if (forField.name === info.volume?.name) { let filter = (u: uPlot, splits: number[]) => { let _splits = []; - let max = u.series[volumeIdx].max as number; + let max = u.series[volumeIdx].max; for (let i = 0; i < splits.length; i++) { _splits.push(splits[i]); - if (splits[i] > max) { + if (max && splits[i] > max) { break; } } @@ -214,7 +214,7 @@ export const CandlestickPanel = ({ if (shouldRenderPrice) { // hide series from legend that are rendered as composite markers for (let key in renderers[0].fieldMap) { - let field = (info as any)[key] as Field; + let field: Field = (info as any)[key]; field.config = { ...field.config, custom: { diff --git a/public/app/plugins/panel/candlestick/module.tsx b/public/app/plugins/panel/candlestick/module.tsx index 408a6e774f3..d4ae7b534a9 100644 --- a/public/app/plugins/panel/candlestick/module.tsx +++ b/public/app/plugins/panel/candlestick/module.tsx @@ -17,21 +17,21 @@ import { CandlestickData, candlestickFieldsInfo, FieldPickerInfo, prepareCandles import { CandlestickSuggestionsSupplier } from './suggestions'; import { defaultCandlestickColors, defaultOptions, Options, VizDisplayMode, ColorStrategy, CandleStyle } from './types'; -const modeOptions = [ +const modeOptions: Array> = [ { label: 'Candles', value: VizDisplayMode.Candles }, { label: 'Volume', value: VizDisplayMode.Volume }, { label: 'Both', value: VizDisplayMode.CandlesVolume }, -] as Array>; +]; -const candleStyles = [ +const candleStyles: Array> = [ { label: 'Candles', value: CandleStyle.Candles }, { label: 'OHLC Bars', value: CandleStyle.OHLCBars }, -] as Array>; +]; -const colorStrategies = [ +const colorStrategies: Array> = [ { label: 'Since Open', value: ColorStrategy.OpenClose }, { label: 'Since Prior Close', value: ColorStrategy.CloseClose }, -] as Array>; +]; const numericFieldFilter = (f: Field) => f.type === FieldType.number; @@ -43,7 +43,7 @@ function addFieldPicker( let placeholderText = 'Auto '; if (data) { - const current = data[info.key] as Field; + const current = data[info.key]; if (current?.config) { placeholderText += '= ' + getFieldDisplayName(current); diff --git a/public/app/plugins/panel/candlestick/utils.ts b/public/app/plugins/panel/candlestick/utils.ts index b0030d0584a..514db67b8f0 100644 --- a/public/app/plugins/panel/candlestick/utils.ts +++ b/public/app/plugins/panel/candlestick/utils.ts @@ -120,12 +120,12 @@ export function drawMarkers(opts: RendererOpts) { let intraDir = Math.sign(cData[i]! - oData[i]!); // volume - if (drawVolume) { + if (drawVolume && flatPathVol && upPathVol && downPathVol) { let outerPath = selectPath( colorStrategy === ColorStrategy.CloseClose ? interDir : intraDir, - flatPathVol as Path2D, - upPathVol as Path2D, - downPathVol as Path2D, + flatPathVol, + upPathVol, + downPathVol, i === idx0 && ColorStrategy.CloseClose ? false : flatAsUp ); @@ -133,12 +133,12 @@ export function drawMarkers(opts: RendererOpts) { outerPath.rect(tPx - halfWidth, vPx, barWidth, zeroPx! - vPx); } - if (drawPrice) { + if (drawPrice && flatPath && upPath && downPath) { let outerPath = selectPath( colorStrategy === ColorStrategy.CloseClose ? interDir : intraDir, - flatPath as Path2D, - upPath as Path2D, - downPath as Path2D, + flatPath, + upPath, + downPath, i === idx0 && ColorStrategy.CloseClose ? false : flatAsUp ); @@ -179,26 +179,26 @@ export function drawMarkers(opts: RendererOpts) { ctx.rect(u.bbox.left, u.bbox.top, u.bbox.width, u.bbox.height); ctx.clip(); - if (drawVolume) { + if (drawVolume && flatPathVol && upPathVol && downPathVol) { ctx.fillStyle = alpha(upColor, volumeAlpha); - ctx.fill(upPathVol as Path2D); + ctx.fill(upPathVol); ctx.fillStyle = alpha(downColor, volumeAlpha); - ctx.fill(downPathVol as Path2D); + ctx.fill(downPathVol); ctx.fillStyle = alpha(flatColor, volumeAlpha); - ctx.fill(flatPathVol as Path2D); + ctx.fill(flatPathVol); } - if (drawPrice) { + if (drawPrice && flatPath && upPath && downPath) { ctx.fillStyle = upColor; - ctx.fill(upPath as Path2D); + ctx.fill(upPath); ctx.fillStyle = downColor; - ctx.fill(downPath as Path2D); + ctx.fill(downPath); ctx.fillStyle = flatColor; - ctx.fill(flatPath as Path2D); + ctx.fill(flatPath); ctx.globalCompositeOperation = 'destination-out'; ctx.fill(hollowPath); diff --git a/public/app/plugins/panel/piechart/suggestions.ts b/public/app/plugins/panel/piechart/suggestions.ts index 0aa156539a1..fd4beed5e6a 100644 --- a/public/app/plugins/panel/piechart/suggestions.ts +++ b/public/app/plugins/panel/piechart/suggestions.ts @@ -1,4 +1,5 @@ import { VisualizationSuggestionsBuilder } from '@grafana/data'; +import { LegendDisplayMode } from '@grafana/schema'; import { SuggestionName } from 'app/types/suggestions'; import { PieChartLabels, Options, PieChartType } from './panelcfg.gen'; @@ -15,14 +16,11 @@ export class PieChartSuggestionsSupplier { }, displayLabels: [PieChartLabels.Percent], legend: { + calcs: [], + displayMode: LegendDisplayMode.Hidden, placement: 'right', values: [], - } as any, - }, - cardOptions: { - previewModifier: (s) => { - // Hide labels in preview - s.options!.legend.showLegend = false; + showLegend: false, }, }, }); diff --git a/public/app/plugins/panel/stat/StatMigrations.ts b/public/app/plugins/panel/stat/StatMigrations.ts index 81a7b5b68cd..4eb5bbdb6c8 100644 --- a/public/app/plugins/panel/stat/StatMigrations.ts +++ b/public/app/plugins/panel/stat/StatMigrations.ts @@ -11,7 +11,7 @@ export const statPanelChangedHandler = ( prevOptions: any ) => { // This handles most config changes - const options = sharedSingleStatPanelChangedHandler(panel, prevPluginId, prevOptions) as Options; + const options: Options = sharedSingleStatPanelChangedHandler(panel, prevPluginId, prevOptions); // Changing from angular singlestat if (prevOptions.angular && (prevPluginId === 'singlestat' || prevPluginId === 'grafana-singlestat-panel')) { diff --git a/public/app/plugins/panel/state-timeline/migrations.ts b/public/app/plugins/panel/state-timeline/migrations.ts index 178a75af7e4..c8762339409 100644 --- a/public/app/plugins/panel/state-timeline/migrations.ts +++ b/public/app/plugins/panel/state-timeline/migrations.ts @@ -10,7 +10,7 @@ export const timelinePanelChangedHandler = ( prevPluginId: string, prevOptions: any ) => { - let options = (panel.options ?? {}) as Options; + let options: Options = panel.options ?? {}; // Changing from angular singlestat if (prevPluginId === 'natel-discrete-panel' && prevOptions.angular) { @@ -34,17 +34,17 @@ export const timelinePanelChangedHandler = ( if (isArray(oldOptions.colorMaps)) { for (const p of oldOptions.colorMaps) { - const color = p.color as string; + const color: string = p.color; if (color) { - valuemap.options[p.text as string] = { color }; + valuemap.options[p.text] = { color }; } } } if (isArray(oldOptions.valueMaps)) { for (const p of oldOptions.valueMaps) { - const text = p.text as string; - const value = p.value as string; + const text: string = p.text; + const value: string = p.value; if (text && value) { let old = valuemap.options[value]; if (old) { @@ -60,7 +60,7 @@ export const timelinePanelChangedHandler = ( for (const p of oldOptions.rangeMaps) { let from = +p.from; let to = +p.to; - const text = p.text as string; + const text: string = p.text; if (text) { fieldConfig.defaults.mappings.push({ type: MappingType.RangeToText, diff --git a/public/app/plugins/panel/table/module.tsx b/public/app/plugins/panel/table/module.tsx index 2e18317877d..e55d1411a43 100644 --- a/public/app/plugins/panel/table/module.tsx +++ b/public/app/plugins/panel/table/module.tsx @@ -138,7 +138,7 @@ export const plugin = new PanelPlugin(TablePanel) path: 'footer.reducer', name: 'Calculation', description: 'Choose a reducer function / calculation', - editor: standardEditorsRegistry.get('stats-picker').editor as any, + editor: standardEditorsRegistry.get('stats-picker').editor, defaultValue: [ReducerID.sum], showIf: (cfg) => cfg.footer?.show, }) @@ -167,7 +167,7 @@ export const plugin = new PanelPlugin(TablePanel) if (field.type === FieldType.number) { const name = getFieldDisplayName(field, frame, context.data); const value = field.name; - options.push({ value, label: name } as any); + options.push({ value, label: name }); } } } diff --git a/public/app/plugins/panel/text/textPanelMigrationHandler.ts b/public/app/plugins/panel/text/textPanelMigrationHandler.ts index 3cd9c7fccfb..0579f3f1d00 100644 --- a/public/app/plugins/panel/text/textPanelMigrationHandler.ts +++ b/public/app/plugins/panel/text/textPanelMigrationHandler.ts @@ -8,9 +8,9 @@ export const textPanelMigrationHandler = (panel: PanelModel): Partial { graph.axisLabel = obj.label; } if (obj.logBase) { - const log = obj.logBase as number; + const log: number = obj.logBase; if (log === 2 || log === 10) { graph.scaleDistribution = { type: ScaleDistribution.Log, @@ -666,7 +666,7 @@ function fillY2DynamicValues( } } -function validNumber(val: any): number | undefined { +function validNumber(val: unknown): number | undefined { if (isNumber(val)) { return val; } diff --git a/public/app/plugins/panel/timeseries/suggestions.ts b/public/app/plugins/panel/timeseries/suggestions.ts index 29989b55544..08c2dfc41f7 100644 --- a/public/app/plugins/panel/timeseries/suggestions.ts +++ b/public/app/plugins/panel/timeseries/suggestions.ts @@ -8,9 +8,9 @@ import { GraphDrawStyle, GraphFieldConfig, GraphGradientMode, + LegendDisplayMode, LineInterpolation, StackingMode, - VizLegendOptions, } from '@grafana/schema'; import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; import { SuggestionName } from 'app/types/suggestions'; @@ -29,7 +29,12 @@ export class TimeSeriesSuggestionsSupplier { name: SuggestionName.LineChart, pluginId: 'timeseries', options: { - legend: {} as VizLegendOptions, + legend: { + calcs: [], + displayMode: LegendDisplayMode.Hidden, + placement: 'right', + showLegend: false, + }, }, fieldConfig: { defaults: { @@ -39,8 +44,6 @@ export class TimeSeriesSuggestionsSupplier { }, cardOptions: { previewModifier: (s) => { - s.options!.legend.showLegend = false; - if (s.fieldConfig?.defaults.custom?.drawStyle !== GraphDrawStyle.Bars) { s.fieldConfig!.defaults.custom!.lineWidth = Math.max(s.fieldConfig!.defaults.custom!.lineWidth ?? 1, 2); } diff --git a/public/app/plugins/panel/trend/suggestions.ts b/public/app/plugins/panel/trend/suggestions.ts index 25eb3b91d2f..c135c5df30e 100644 --- a/public/app/plugins/panel/trend/suggestions.ts +++ b/public/app/plugins/panel/trend/suggestions.ts @@ -1,5 +1,5 @@ import { VisualizationSuggestionsBuilder } from '@grafana/data'; -import { GraphDrawStyle, GraphFieldConfig, VizLegendOptions } from '@grafana/schema'; +import { GraphDrawStyle, GraphFieldConfig, LegendDisplayMode } from '@grafana/schema'; import { SuggestionName } from 'app/types/suggestions'; import { Options } from './panelcfg.gen'; @@ -17,7 +17,12 @@ export class TrendSuggestionsSupplier { name: SuggestionName.LineChart, pluginId: 'trend', options: { - legend: {} as VizLegendOptions, + legend: { + calcs: [], + displayMode: LegendDisplayMode.Hidden, + placement: 'right', + showLegend: false, + }, }, fieldConfig: { defaults: { @@ -27,8 +32,6 @@ export class TrendSuggestionsSupplier { }, cardOptions: { previewModifier: (s) => { - s.options!.legend.showLegend = false; - if (s.fieldConfig?.defaults.custom?.drawStyle !== GraphDrawStyle.Bars) { s.fieldConfig!.defaults.custom!.lineWidth = Math.max(s.fieldConfig!.defaults.custom!.lineWidth ?? 1, 2); }