Chore: some type fixes (#59030)

some type fixes
This commit is contained in:
Ashley Harrison 2022-11-29 15:52:08 +00:00 committed by GitHub
parent f485f8a8f8
commit 191ca1df86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 81 additions and 119 deletions

View File

@ -7567,24 +7567,13 @@ 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/plugins/panel/nodeGraph/useCategorizeFrames.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/plugins/panel/nodeGraph/usePanning.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, "Do not use any type assertions.", "3"]
],
"public/app/plugins/panel/nodeGraph/useZoom.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/plugins/panel/nodeGraph/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, "Unexpected any. Specify a different type.", "2"]
],
"public/app/plugins/panel/piechart/PieChart.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
@ -7597,25 +7586,16 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/plugins/panel/stat/StatMigrations.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.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"]
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"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"]
],
"public/app/plugins/panel/stat/common.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/state-timeline/TimelineChart.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.", "1"]
],
"public/app/plugins/panel/state-timeline/migrations.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -7638,23 +7618,10 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/plugins/panel/state-timeline/utils.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.", "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.", "0"]
],
"public/app/plugins/panel/state-timeline/utils.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, "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.", "0"]
],
"public/app/plugins/panel/table-old/column_options.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -8020,16 +7987,10 @@ exports[`better eslint`] = {
"public/test/core/redux/reduxTester.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, "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, "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.", "11"]
[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"]
],
"public/test/core/thunk/thunkTester.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -8043,43 +8004,32 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "8"]
],
"public/test/global-jquery-shim.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/test/helpers/convertToStoreState.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"]
],
"public/test/helpers/createFetchResponse.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.", "0"]
],
"public/test/helpers/getDashboardModel.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/test/helpers/initTemplateSrv.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/test/jest-setup.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[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.", "2"]
],
"public/test/jest-shim.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[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, "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.", "5"]
],
"public/test/lib/common.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/test/matchers/index.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@ -8103,10 +8053,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "4"]
],
"public/test/matchers/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.", "0"]
],
"public/test/mocks/angular.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -8123,16 +8070,11 @@ exports[`better eslint`] = {
],
"public/test/mocks/datasource_srv.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"],
[0, 0, 0, "Do not use any type assertions.", "5"]
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/test/mocks/workers.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, "Unexpected any. Specify a different type.", "1"]
],
"public/test/specs/helpers.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -8144,14 +8086,13 @@ 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, "Do not use any type assertions.", "9"],
[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.", "15"]
]
}`
};

View File

@ -36,7 +36,10 @@ function countEslintErrors() {
};
const isTestFile =
filePath.endsWith('.test.tsx') || filePath.endsWith('.test.ts') || filePath.includes('__mocks__');
filePath.endsWith('.test.tsx') ||
filePath.endsWith('.test.ts') ||
filePath.includes('__mocks__') ||
filePath.includes('public/test/');
if (!isTestFile) {
rules['@typescript-eslint/consistent-type-assertions'] = [

View File

@ -9,7 +9,10 @@ import { DataFrame } from '@grafana/data';
*/
export function useCategorizeFrames(series: DataFrame[]) {
return useMemo(() => {
return series.reduce(
return series.reduce<{
nodes: DataFrame[];
edges: DataFrame[];
}>(
(acc, frame) => {
const sourceField = frame.fields.filter((f) => f.name === 'source');
if (sourceField.length) {
@ -19,7 +22,7 @@ export function useCategorizeFrames(series: DataFrame[]) {
}
return acc;
},
{ edges: [], nodes: [] } as { nodes: DataFrame[]; edges: DataFrame[] }
{ edges: [], nodes: [] }
);
}, [series]);
}

View File

@ -44,14 +44,13 @@ export function useZoom({ stepUp, stepDown, min, max } = defaultOptions) {
}, [scale, stepDown, min]);
const onWheel = useCallback(
function (event: Event) {
function (wheelEvent: WheelEvent) {
// Seems like typing for the addEventListener is lacking a bit
const wheelEvent = event as WheelEvent;
// Only do this with special key pressed similar to how google maps work.
// TODO: I would guess this won't work very well with touch right now
if (wheelEvent.ctrlKey || wheelEvent.metaKey) {
event.preventDefault();
wheelEvent.preventDefault();
setScale(Math.min(Math.max(min ?? -Infinity, scale + Math.min(wheelEvent.deltaY, 2) * -0.01), max ?? Infinity));

View File

@ -213,7 +213,7 @@ function processEdges(edges: DataFrame, edgeFields: EdgeFields): EdgeDatum[] {
secondaryStat: edgeFields.secondaryStat
? statToString(edgeFields.secondaryStat.config, edgeFields.secondaryStat.values.get(index))
: '',
} as EdgeDatum;
};
});
}

View File

@ -199,7 +199,7 @@ function PieSlice({ arc, pie, highlightState, openMenu, fill, tooltip, tooltipOp
const { eventBus } = usePanelContext();
const onMouseOut = useCallback(
(event: any) => {
(event: React.MouseEvent<SVGGElement>) => {
eventBus?.publish({
type: DataHoverClearEvent.type,
payload: {
@ -215,7 +215,7 @@ function PieSlice({ arc, pie, highlightState, openMenu, fill, tooltip, tooltipOp
);
const onMouseMoveOverArc = useCallback(
(event: any) => {
(event: React.MouseEvent<SVGGElement>) => {
eventBus?.publish({
type: DataHoverEvent.type,
payload: {
@ -226,12 +226,16 @@ function PieSlice({ arc, pie, highlightState, openMenu, fill, tooltip, tooltipOp
},
});
const coords = localPoint(event.target.ownerSVGElement, event);
tooltip.showTooltip({
tooltipLeft: coords!.x,
tooltipTop: coords!.y,
tooltipData: getTooltipData(pie, arc, tooltipOptions),
});
const owner = event.currentTarget.ownerSVGElement;
if (owner) {
const coords = localPoint(owner, event);
tooltip.showTooltip({
tooltipLeft: coords!.x,
tooltipTop: coords!.y,
tooltipData: getTooltipData(pie, arc, tooltipOptions),
});
}
},
[eventBus, arc, tooltip, pie, tooltipOptions]
);

View File

@ -5,7 +5,7 @@ import { statPanelChangedHandler } from './StatMigrations';
describe('Stat Panel Migrations', () => {
it('change from angular singlestat sparkline disabled', () => {
const old: any = {
const old = {
angular: {
format: 'ms',
decimals: 7,
@ -21,7 +21,7 @@ describe('Stat Panel Migrations', () => {
});
it('change from angular singlestat sparkline enabled', () => {
const old: any = {
const old = {
angular: {
format: 'ms',
decimals: 7,
@ -37,7 +37,7 @@ describe('Stat Panel Migrations', () => {
});
it('change from angular singlestat color background', () => {
const old: any = {
const old = {
angular: {
format: 'ms',
decimals: 7,
@ -51,7 +51,7 @@ describe('Stat Panel Migrations', () => {
});
it('change from angular singlestat with name stat', () => {
const old: any = {
const old = {
angular: {
valueName: 'name',
},

View File

@ -50,7 +50,7 @@ export function addStandardDataReduceOptions<T extends SingleStatBaseOptions>(
name: 'Calculation',
description: 'Choose a reducer function / calculation',
category: valueOptionsCategory,
editor: standardEditorsRegistry.get('stats-picker').editor as any,
editor: standardEditorsRegistry.get('stats-picker').editor,
// TODO: Get ReducerID from generated schema one day?
defaultValue: [ReducerID.lastNotNull],
// Hides it when all values mode is on

View File

@ -50,7 +50,7 @@ export class TimelineChart extends React.Component<TimelineProps> {
};
prepConfig = (alignedFrame: DataFrame, allFrames: DataFrame[], getTimeRange: () => TimeRange) => {
this.panelContext = this.context as PanelContext;
this.panelContext = this.context;
const { eventBus, sync } = this.panelContext;
return preparePlotConfigBuilder({

View File

@ -1,5 +1,5 @@
import { ArrayVector, createTheme, FieldType, ThresholdsMode, TimeRange, toDataFrame, dateTime } from '@grafana/data';
import { LegendDisplayMode } from '@grafana/schema';
import { LegendDisplayMode, VizLegendOptions } from '@grafana/schema';
import {
findNextStateIndex,
@ -15,7 +15,10 @@ describe('prepare timeline graph', () => {
const timeRange: TimeRange = {
from: dateTime(1),
to: dateTime(3),
raw: {} as any,
raw: {
from: dateTime(1),
to: dateTime(3),
},
};
it('errors with no time fields', () => {
const frames = [
@ -92,7 +95,8 @@ describe('findNextStateIndex', () => {
name: 'time',
type: FieldType.number,
values: new ArrayVector([1, undefined, undefined, 2, undefined, undefined]),
} as any;
config: {},
};
const result = findNextStateIndex(field, 0);
expect(result).toEqual(3);
});
@ -102,7 +106,8 @@ describe('findNextStateIndex', () => {
name: 'time',
type: FieldType.number,
values: new ArrayVector([1, undefined, undefined, 2, undefined, 3]),
} as any;
config: {},
};
const result = findNextStateIndex(field, 5);
expect(result).toEqual(null);
});
@ -112,7 +117,8 @@ describe('findNextStateIndex', () => {
name: 'time',
type: FieldType.number,
values: new ArrayVector([1, undefined, undefined, 2, undefined, 3, undefined]),
} as any;
config: {},
};
const result = findNextStateIndex(field, 5);
expect(result).toEqual(null);
});
@ -134,7 +140,8 @@ describe('findNextStateIndex', () => {
undefined,
undefined,
]),
} as any;
config: {},
};
const result = findNextStateIndex(field, 3);
expect(result).toEqual(8);
});
@ -144,7 +151,8 @@ describe('findNextStateIndex', () => {
name: 'time',
type: FieldType.number,
values: new ArrayVector([1, 3, 2]),
} as any;
config: {},
};
test('leading', () => {
const result = findNextStateIndex(field, 0);
@ -232,7 +240,11 @@ describe('prepareTimelineLegendItems', () => {
},
];
const result = prepareTimelineLegendItems(frame, { displayMode: LegendDisplayMode.List } as any, theme);
const result = prepareTimelineLegendItems(
frame,
{ displayMode: LegendDisplayMode.List } as VizLegendOptions,
theme
);
expect(result).toHaveLength(1);
});

View File

@ -209,7 +209,7 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<TimelineOptions> = ({
}
const field = frame.fields[i];
const config = field.config as FieldConfig<TimelineFieldConfig>;
const config: FieldConfig<TimelineFieldConfig> = field.config;
const customConfig: TimelineFieldConfig = {
...defaultConfig,
...config.custom,
@ -259,8 +259,7 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<TimelineOptions> = ({
return true;
},
},
//TODO: remove any once https://github.com/leeoniya/uPlot/pull/611 got merged or the typing is fixed
scales: [xScaleKey, null as any],
scales: [xScaleKey, null],
};
builder.setSync();
builder.setCursor(cursor);
@ -284,9 +283,9 @@ export function getNamesToFieldIndex(frame: DataFrame): Map<string, number> {
* in: 1, 1,undefined, 1,2, 2,null,2,3
* out: 1,undefined,undefined,undefined,2,undefined,null,2,3
*/
export function unsetSameFutureValues(values: any[]): any[] | undefined {
export function unsetSameFutureValues(values: unknown[]): unknown[] | undefined {
let prevVal = values[0];
let clone: any[] | undefined = undefined;
let clone: unknown[] | undefined = undefined;
for (let i = 1; i < values.length; i++) {
let value = values[i];

View File

@ -1,6 +1,7 @@
import { DashboardModel } from '../../app/features/dashboard/state';
import { DashboardMeta } from '../../app/types/dashboard';
export const getDashboardModel = (json: any, meta: any = {}) => {
export const getDashboardModel = (json: any, meta: DashboardMeta = {}) => {
const getVariablesFromState = () => json.templating.list;
return new DashboardModel(json, meta, getVariablesFromState);
};

View File

@ -22,7 +22,7 @@ export function forceObservableCompletion(subscription: Subscription, resolve: (
);
}
export function expectObservableToBeDefined(received: any): jest.CustomMatcherResult | null {
export function expectObservableToBeDefined(received: unknown): jest.CustomMatcherResult | null {
if (received) {
return null;
}
@ -35,7 +35,7 @@ Expected ${printReceived(received)} to be ${printExpected('defined')}.`,
};
}
export function expectObservableToBeObservable(received: any): jest.CustomMatcherResult | null {
export function expectObservableToBeObservable(received: unknown): jest.CustomMatcherResult | null {
if (isObservable(received)) {
return null;
}
@ -48,7 +48,7 @@ Expected ${printReceived(received)} to be ${printExpected('an Observable')}.`,
};
}
export function expectObservable(received: any): jest.CustomMatcherResult | null {
export function expectObservable(received: unknown): jest.CustomMatcherResult | null {
const toBeDefined = expectObservableToBeDefined(received);
if (toBeDefined) {
return toBeDefined;