From 963fffeef10cdad8276e46c6a20f2a13b0491c31 Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Mon, 14 Aug 2023 16:04:04 +0100 Subject: [PATCH] Chore: fix some more types (#72726) fix some more types --- .betterer.results | 82 ++++--------------- .../app/features/alerting/state/alertDef.ts | 2 +- .../features/dashboard/services/TimeSrv.ts | 2 +- .../app/features/datasources/state/actions.ts | 2 +- .../editors/ResourceDimensionEditor.tsx | 4 +- .../editors/TextDimensionEditor.tsx | 8 +- .../TraceTimelineViewer/ListView/index.tsx | 46 ++++++----- .../components/common/BreakableText.tsx | 8 +- .../components/model/link-patterns.tsx | 2 +- .../expressions/components/Condition.tsx | 11 ++- .../app/features/geo/gazetteer/gazetteer.ts | 2 +- .../features/inspector/InspectDataOptions.tsx | 7 +- .../app/features/inspector/InspectJSONTab.tsx | 2 +- .../app/features/inspector/QueryInspector.tsx | 8 -- public/app/features/library-panels/utils.ts | 2 +- .../live/centrifuge/LiveDataStream.ts | 6 +- .../app/features/live/centrifuge/channel.ts | 10 +-- .../app/features/live/centrifuge/service.ts | 15 +++- .../live/centrifuge/transferHandlers.ts | 4 +- public/app/features/logs/utils.ts | 8 +- .../components/ImportDashboardForm.tsx | 12 +-- 21 files changed, 98 insertions(+), 145 deletions(-) diff --git a/.betterer.results b/.betterer.results index 6359886fbbe..7017aa6a84f 100644 --- a/.betterer.results +++ b/.betterer.results @@ -2236,9 +2236,6 @@ exports[`better eslint`] = { "public/app/features/dashboard/services/PublicDashboardDataSource.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/dashboard/services/TimeSrv.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/dashboard/state/DashboardMigrator.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -2455,8 +2452,7 @@ exports[`better eslint`] = { ], "public/app/features/datasources/state/actions.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"] + [0, 0, 0, "Do not use any type assertions.", "1"] ], "public/app/features/datasources/state/navModel.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], @@ -2474,14 +2470,11 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "0"] ], "public/app/features/dimensions/editors/ResourceDimensionEditor.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.", "0"] ], "public/app/features/dimensions/editors/TextDimensionEditor.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"] + [0, 0, 0, "Do not use any type assertions.", "1"] ], "public/app/features/dimensions/editors/ThresholdsEditor/ThresholdsEditor.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -2518,12 +2511,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "4"], [0, 0, 0, "Do not use any type assertions.", "5"] ], - "public/app/features/explore/TraceView/components/TraceTimelineViewer/ListView/index.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], - "public/app/features/explore/TraceView/components/common/BreakableText.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/explore/TraceView/components/demo/trace-generators.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], @@ -2541,11 +2528,10 @@ 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, "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, "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"] ], "public/app/features/explore/TraceView/components/model/transform-trace-data.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -2583,9 +2569,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "1"], [0, 0, 0, "Do not use any type assertions.", "2"] ], - "public/app/features/expressions/components/Condition.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/expressions/guards.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], @@ -2600,9 +2583,7 @@ exports[`better eslint`] = { ], "public/app/features/geo/gazetteer/gazetteer.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, "Do not use any type assertions.", "1"] ], "public/app/features/geo/gazetteer/worldmap.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -2613,10 +2594,7 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "2"] ], "public/app/features/inspector/InspectDataOptions.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, "Do not use any type assertions.", "3"] + [0, 0, 0, "Do not use any type assertions.", "0"] ], "public/app/features/inspector/InspectDataTab.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] @@ -2625,8 +2603,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/features/inspector/InspectJSONTab.tsx:5381": [ - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] + [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] ], "public/app/features/inspector/InspectStatsTab.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] @@ -2635,9 +2612,8 @@ 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, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "4"], - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "5"] + [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "3"], + [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "4"] ], "public/app/features/invites/state/selectors.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -2646,8 +2622,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/features/library-panels/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.", "0"] ], "public/app/features/live/centrifuge/LiveDataStream.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -2659,29 +2634,17 @@ exports[`better eslint`] = { ], "public/app/features/live/centrifuge/LiveDataStream.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, "Do not use any type assertions.", "1"] ], "public/app/features/live/centrifuge/channel.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Do not use any type assertions.", "4"] - ], - "public/app/features/live/centrifuge/service.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/features/live/centrifuge/serviceWorkerProxy.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/live/centrifuge/transferHandlers.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.", "0"] ], "public/app/features/live/data/amendTimeSeries.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -2694,19 +2657,10 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "0"] ], "public/app/features/logs/utils.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"], - [0, 0, 0, "Do not use any type assertions.", "4"] + [0, 0, 0, "Do not use any type assertions.", "0"] ], "public/app/features/manage-dashboards/components/ImportDashboardForm.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"], - [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.", "0"] ], "public/app/features/manage-dashboards/components/ImportDashboardLibraryPanelsList.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] diff --git a/public/app/features/alerting/state/alertDef.ts b/public/app/features/alerting/state/alertDef.ts index e531791cba6..50af697cef3 100644 --- a/public/app/features/alerting/state/alertDef.ts +++ b/public/app/features/alerting/state/alertDef.ts @@ -63,7 +63,7 @@ const reducerTypes = [ { text: 'percent_diff()', value: 'percent_diff' }, { text: 'percent_diff_abs()', value: 'percent_diff_abs' }, { text: 'count_non_null()', value: 'count_non_null' }, -]; +] as const; const noDataModes = [ { text: 'Alerting', value: 'alerting' }, diff --git a/public/app/features/dashboard/services/TimeSrv.ts b/public/app/features/dashboard/services/TimeSrv.ts index 073f707feb0..4ab6dfae24e 100644 --- a/public/app/features/dashboard/services/TimeSrv.ts +++ b/public/app/features/dashboard/services/TimeSrv.ts @@ -238,7 +238,7 @@ export class TimeSrv { if (interval === AutoRefreshInterval) { intervalMs = this.getAutoRefreshInteval().intervalMs; } else { - refresh = this.contextSrv.getValidInterval(interval as string); + refresh = this.contextSrv.getValidInterval(interval); intervalMs = rangeUtil.intervalToMs(refresh); } diff --git a/public/app/features/datasources/state/actions.ts b/public/app/features/datasources/state/actions.ts index 1e7f9d769ad..fa29b0b2257 100644 --- a/public/app/features/datasources/state/actions.ts +++ b/public/app/features/datasources/state/actions.ts @@ -210,7 +210,7 @@ export function loadDataSource(uid: string): ThunkResult { return async (dispatch) => { - const pluginInfo = (await getPluginSettings(dataSource.type)) as DataSourcePluginMeta; + const pluginInfo: DataSourcePluginMeta = await getPluginSettings(dataSource.type); const plugin = await importDataSourcePlugin(pluginInfo); const isBackend = plugin.DataSourceClass.prototype instanceof DataSourceWithBackend; const meta = { diff --git a/public/app/features/dimensions/editors/ResourceDimensionEditor.tsx b/public/app/features/dimensions/editors/ResourceDimensionEditor.tsx index 82d02f10c5d..4141fe73a79 100644 --- a/public/app/features/dimensions/editors/ResourceDimensionEditor.tsx +++ b/public/app/features/dimensions/editors/ResourceDimensionEditor.tsx @@ -16,9 +16,9 @@ const resourceOptions = [ // { label: 'Mapping', value: ResourceDimensionMode.Mapping, description: 'Map the results of a value to an svg' }, ]; -const dummyFieldSettings: StandardEditorsRegistryItem = { +const dummyFieldSettings = { settings: {}, -} as any; +} as StandardEditorsRegistryItem; export const ResourceDimensionEditor = ( props: StandardEditorProps diff --git a/public/app/features/dimensions/editors/TextDimensionEditor.tsx b/public/app/features/dimensions/editors/TextDimensionEditor.tsx index f0958ac440e..65b12180e54 100644 --- a/public/app/features/dimensions/editors/TextDimensionEditor.tsx +++ b/public/app/features/dimensions/editors/TextDimensionEditor.tsx @@ -19,13 +19,13 @@ const textOptions = [ // { label: 'Template', value: TextDimensionMode.Template, description: 'use template text' }, ]; -const dummyFieldSettings: StandardEditorsRegistryItem = { +const dummyFieldSettings = { settings: {}, -} as any; +} as StandardEditorsRegistryItem; -const dummyStringSettings: StandardEditorsRegistryItem = { +const dummyStringSettings = { settings: {}, -} as any; +} as StandardEditorsRegistryItem; type Props = StandardEditorProps; diff --git a/public/app/features/explore/TraceView/components/TraceTimelineViewer/ListView/index.tsx b/public/app/features/explore/TraceView/components/TraceTimelineViewer/ListView/index.tsx index 346f84469bc..67ae5344c5e 100644 --- a/public/app/features/explore/TraceView/components/TraceTimelineViewer/ListView/index.tsx +++ b/public/app/features/explore/TraceView/components/TraceTimelineViewer/ListView/index.tsx @@ -378,28 +378,30 @@ export default class ListView extends React.Component { const nodes = this._itemHolderElm.childNodes; const max = nodes.length; for (let i = 0; i < max; i++) { - const node = nodes[i] as HTMLElement; - // use `.getAttribute(...)` instead of `.dataset` for jest / JSDOM - const itemKey = node.getAttribute('data-item-key'); - if (!itemKey) { - // eslint-disable-next-line no-console - console.warn('itemKey not found'); - continue; - } - // measure the first child, if it's available, otherwise the node itself - // (likely not transferable to other contexts, and instead is specific to - // how we have the items rendered) - const measureSrc: Element = node.firstElementChild || node; - const observed = measureSrc.clientHeight; - const known = this._knownHeights.get(itemKey); - if (observed !== known) { - this._knownHeights.set(itemKey, observed); - if (!isDirty) { - isDirty = true; - // eslint-disable-next-line no-multi-assign - lowDirtyKey = highDirtyKey = itemKey; - } else { - highDirtyKey = itemKey; + const node = nodes[i]; + if (node instanceof HTMLElement) { + // use `.getAttribute(...)` instead of `.dataset` for jest / JSDOM + const itemKey = node.getAttribute('data-item-key'); + if (!itemKey) { + // eslint-disable-next-line no-console + console.warn('itemKey not found'); + continue; + } + // measure the first child, if it's available, otherwise the node itself + // (likely not transferable to other contexts, and instead is specific to + // how we have the items rendered) + const measureSrc: Element = node.firstElementChild || node; + const observed = measureSrc.clientHeight; + const known = this._knownHeights.get(itemKey); + if (observed !== known) { + this._knownHeights.set(itemKey, observed); + if (!isDirty) { + isDirty = true; + // eslint-disable-next-line no-multi-assign + lowDirtyKey = highDirtyKey = itemKey; + } else { + highDirtyKey = itemKey; + } } } } diff --git a/public/app/features/explore/TraceView/components/common/BreakableText.tsx b/public/app/features/explore/TraceView/components/common/BreakableText.tsx index 26ad069eb40..2893bcf119f 100644 --- a/public/app/features/explore/TraceView/components/common/BreakableText.tsx +++ b/public/app/features/explore/TraceView/components/common/BreakableText.tsx @@ -35,11 +35,7 @@ type Props = { wordRegexp?: RegExp; }; -// TODO typescript doesn't understand text or null as react nodes -// https://github.com/Microsoft/TypeScript/issues/21699 -export default function BreakableText( - props: Props -): any /* React.ReactNode /* React.ReactElement | React.ReactElement[] \*\/ */ { +export default function BreakableText(props: Props): React.ReactElement | null { const { className, text, wordRegexp = WORD_RX } = props; const styles = useStyles2(getStyles); if (!text) { @@ -57,7 +53,7 @@ export default function BreakableText( ); match = wordRegexp.exec(text); } - return spans; + return <>{spans}; } BreakableText.defaultProps = { diff --git a/public/app/features/explore/TraceView/components/model/link-patterns.tsx b/public/app/features/explore/TraceView/components/model/link-patterns.tsx index b26b18fc910..930fc541056 100644 --- a/public/app/features/explore/TraceView/components/model/link-patterns.tsx +++ b/public/app/features/explore/TraceView/components/model/link-patterns.tsx @@ -73,7 +73,7 @@ export function processTemplate(template: unknown, encodeFn: (unencoded: any) => }; } -export function createTestFunction(entry?: any) { +export function createTestFunction(entry?: unknown) { if (typeof entry === 'string') { return (arg: unknown) => arg === entry; } diff --git a/public/app/features/expressions/components/Condition.tsx b/public/app/features/expressions/components/Condition.tsx index 8aa8457b811..82dbb93c682 100644 --- a/public/app/features/expressions/components/Condition.tsx +++ b/public/app/features/expressions/components/Condition.tsx @@ -16,7 +16,10 @@ interface Props { refIds: Array>; } -const reducerFunctions = alertDef.reducerTypes.map((rt) => ({ label: rt.text, value: rt.value })); +const reducerFunctions = alertDef.reducerTypes.map<{ + label: string; + value: ReducerType; +}>((rt) => ({ label: rt.text, value: rt.value })); const evalOperators = alertDef.evalOperators.map((eo) => ({ label: eo.text, value: eo.value })); const evalFunctions = alertDef.evalFunctions.map((ef) => ({ label: ef.text, value: ef.value })); @@ -30,10 +33,10 @@ export const Condition = ({ condition, index, onChange, onRemoveCondition, refId }); }; - const onReducerFunctionChange = (conditionFunction: SelectableValue) => { + const onReducerFunctionChange = (conditionFunction: SelectableValue) => { onChange({ ...condition, - reducer: { type: conditionFunction.value! as ReducerType, params: [] }, + reducer: { type: conditionFunction.value!, params: [] }, }); }; @@ -83,7 +86,7 @@ export const Condition = ({ condition, index, onChange, onRemoveCondition, refId value={evalOperators.find((ea) => ea.value === condition.operator!.type)} /> )} - + ); })}