Chore: type fixes (#72604)

* fixing some types

* some more type fixes

* undo rootReducer type change

* update betterer
This commit is contained in:
Ashley Harrison 2023-08-01 12:56:21 +01:00 committed by GitHub
parent 148b6186b7
commit a0b0d704d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 73 additions and 146 deletions

View File

@ -902,9 +902,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "2"]
],
"packages/grafana-ui/src/components/DataLinks/DataLinkInput.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, "Unexpected any. Specify a different type.", "2"]
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"packages/grafana-ui/src/components/DataLinks/DataLinksContextMenu.tsx:5381": [
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
@ -926,9 +924,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"]
],
"packages/grafana-ui/src/components/DateTimePickers/TimeOfDayPicker.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"packages/grafana-ui/src/components/DateTimePickers/TimeRangeInput.tsx:5381": [
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
],
@ -955,20 +950,11 @@ exports[`better eslint`] = {
"packages/grafana-ui/src/components/Forms/FieldArray.story.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"packages/grafana-ui/src/components/Forms/Form.story.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"]
],
"packages/grafana-ui/src/components/Forms/Legacy/Input/Input.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"]
],
"packages/grafana-ui/src/components/Forms/Legacy/Select/IndicatorsContainer.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"packages/grafana-ui/src/components/Forms/Legacy/Select/Select.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
@ -977,8 +963,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"packages/grafana-ui/src/components/Graph/Graph.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.", "0"]
],
"packages/grafana-ui/src/components/Graph/GraphContextMenu.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@ -1586,8 +1571,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/core/reducers/root.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/core/services/ResponseQueue.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@ -3156,21 +3140,14 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
],
"public/app/features/transformers/configFromQuery/ConfigFromQueryTransformerEditor.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/transformers/editors/CalculateFieldTransformerEditor.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/transformers/editors/ConvertFieldTypeTransformerEditor.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/transformers/editors/GroupByTransformerEditor.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/transformers/editors/OrganizeFieldsTransformerEditor.tsx:5381": [
"public/app/features/transformers/editors/GroupByTransformerEditor.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/transformers/editors/ReduceTransformerEditor.tsx:5381": [
@ -3205,15 +3182,10 @@ 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/features/transformers/lookupGazetteer/FieldLookupTransformerEditor.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.", "0"]
],
"public/app/features/transformers/lookupGazetteer/fieldLookup.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@ -3226,28 +3198,17 @@ 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/transformers/spatial/SpatialTransformerEditor.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/transformers/spatial/optionsHelper.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Do not use any type assertions.", "2"],
[0, 0, 0, "Do not use any type assertions.", "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, "Do not use any type assertions.", "5"],
[0, 0, 0, "Do not use any type assertions.", "6"]
],
"public/app/features/transformers/spatial/utils.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
[0, 0, 0, "Do not use any type assertions.", "4"],
[0, 0, 0, "Do not use any type assertions.", "5"]
],
"public/app/features/transformers/standardTransformers.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/transformers/utils.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/users/state/reducers.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
@ -3502,9 +3463,8 @@ exports[`better eslint`] = {
],
"public/app/features/variables/state/sharedReducer.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.", "3"]
[0, 0, 0, "Do not use any type assertions.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
],
"public/app/features/variables/state/transactionReducer.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -3530,9 +3490,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"]
],
"public/app/features/variables/textbox/reducer.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/variables/types.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
@ -3551,9 +3508,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
[0, 0, 0, "Do not use any type assertions.", "12"]
[0, 0, 0, "Do not use any type assertions.", "10"]
],
"public/app/plugins/datasource/alertmanager/DataSource.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@ -5601,9 +5556,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "10"],
[0, 0, 0, "Do not use any type assertions.", "11"]
],
"public/app/polyfills/old-mediaquerylist.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/store/configureStore.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],

1
.github/CODEOWNERS vendored
View File

@ -436,7 +436,6 @@ lerna.json @grafana/frontend-ops
/public/app/plugins/panel/welcome/ @grafana/grafana-frontend-platform
/public/app/plugins/panel/xychart/ @grafana/dataviz-squad
/public/app/plugins/sdk.ts @grafana/plugins-platform-frontend
/public/app/polyfills/old-mediaquerylist.ts @grafana/grafana-frontend-platform
/public/app/routes/ @grafana/grafana-frontend-platform
/public/app/store/ @grafana/grafana-frontend-platform
/public/app/types/ @grafana/grafana-frontend-platform

View File

@ -38,7 +38,7 @@ const datalinksSyntax: Grammar = {
const plugins = [
SlatePrism(
{
onlyIn: (node: any) => node.type === 'code_block',
onlyIn: (node) => 'type' in node && node.type === 'code_block',
getSyntax: () => 'links',
},
{ ...(Prism.languages as LanguageMap), links: datalinksSyntax }
@ -100,7 +100,7 @@ export const DataLinkInput = memo(
// SelectionReference is used to position the variables suggestion relatively to current DOM selection
const selectionRef = useMemo(() => new SelectionReference(), []);
const onKeyDown = React.useCallback((event: React.KeyboardEvent, next: () => any) => {
const onKeyDown = React.useCallback((event: React.KeyboardEvent, next: () => void) => {
if (!stateRef.current.showingSuggestions) {
if (event.key === '=' || event.key === '$' || (event.keyCode === 32 && event.ctrlKey)) {
return setShowingSuggestions(true);

View File

@ -2,7 +2,7 @@ import { css, cx } from '@emotion/css';
import RcTimePicker from 'rc-time-picker';
import React from 'react';
import { dateTime, DateTime, dateTimeAsMoment, GrafanaTheme2 } from '@grafana/data';
import { dateTime, DateTime, dateTimeAsMoment, GrafanaTheme2, isDateTimeInput } from '@grafana/data';
import { Icon, useStyles2 } from '../../index';
import { getFocusStyles } from '../../themes/mixins';
@ -43,7 +43,11 @@ export const TimeOfDayPicker = ({
className={cx(inputSizes()[size], styles.input)}
popupClassName={cx(styles.picker, POPUP_CLASS_NAME)}
defaultValue={dateTimeAsMoment()}
onChange={(value: any) => onChange(dateTime(value))}
onChange={(value) => {
if (isDateTimeInput(value)) {
return onChange(dateTime(value));
}
}}
allowEmpty={false}
showSecond={showSeconds}
value={dateTimeAsMoment(value)}

View File

@ -67,8 +67,9 @@ const renderForm = (defaultValues?: FormDTO) => (
console.log(data);
}}
>
{({ register, control, errors }) =>
(console.log(errors) as any) || (
{({ register, control, errors }) => {
console.log(errors);
return (
<>
<Legend>Edit user</Legend>
@ -120,8 +121,8 @@ const renderForm = (defaultValues?: FormDTO) => (
<Button type="submit">Update</Button>
</>
)
}
);
}}
</Form>
);
@ -153,8 +154,9 @@ export const AsyncValidation: Story = ({ passAsyncValidation }) => {
alert('Submitted successfully!');
}}
>
{({ register, control, errors, formState }) =>
(console.log(errors) as any) || (
{({ register, control, errors, formState }) => {
console.log(errors);
return (
<>
<Legend>Edit user</Legend>
@ -169,8 +171,8 @@ export const AsyncValidation: Story = ({ passAsyncValidation }) => {
Submit
</Button>
</>
)
}
);
}}
</Form>
</>
);

View File

@ -1,9 +1,9 @@
import React from 'react';
import { components } from 'react-select';
import { components, IndicatorsContainerProps } from 'react-select';
import { Icon } from '../../../Icon/Icon';
export const IndicatorsContainer = (props: any) => {
export const IndicatorsContainer = (props: IndicatorsContainerProps) => {
const isOpen = props.selectProps.menuIsOpen;
return (
<components.IndicatorsContainer {...props}>

View File

@ -299,7 +299,7 @@ export class Graph extends PureComponent<GraphProps, GraphState> {
const max = timeRange.to.valueOf();
const yaxes = this.getYAxes(series);
const flotOptions: any = {
const flotOptions = {
legend: {
show: false,
},

View File

@ -3,7 +3,6 @@ import 'core-js';
import 'regenerator-runtime/runtime';
import 'whatwg-fetch'; // fetch polyfill needed for PhantomJs rendering
import './polyfills/old-mediaquerylist'; // Safari < 14 does not have mql.addEventListener()
import 'file-saver';
import 'jquery';

View File

@ -1,3 +1,4 @@
import { ReducersMapObject } from '@reduxjs/toolkit';
import { AnyAction, combineReducers } from 'redux';
import sharedReducers from 'app/core/reducers';
@ -58,7 +59,7 @@ const rootReducers = {
const addedReducers = {};
export const addReducer = (newReducers: any) => {
export const addReducer = (newReducers: ReducersMapObject) => {
Object.assign(addedReducers, newReducers);
};

View File

@ -42,7 +42,7 @@ export function ConfigFromQueryTransformerEditor({ input, onChange, options }: P
onChange({ ...options, applyTo: { id: value.value! } });
};
const onMatcherConfigChange = (matcherOption: any) => {
const onMatcherConfigChange = (matcherOption: unknown) => {
onChange({ ...options, applyTo: { id: currentMatcher.id, options: matcherOption } });
};

View File

@ -21,9 +21,9 @@ import { allFieldTypeIconOptions } from '@grafana/ui/src/components/MatchersUI/F
import { hasAlphaPanels } from 'app/core/config';
import { findField } from 'app/features/dimensions';
const fieldNamePickerSettings: StandardEditorsRegistryItem<string, FieldNamePickerConfigSettings> = {
const fieldNamePickerSettings = {
settings: { width: 24, isClearable: false },
} as any;
} as StandardEditorsRegistryItem<string, FieldNamePickerConfigSettings>;
export const ConvertFieldTypeTransformerEditor = ({
input,

View File

@ -192,13 +192,10 @@ const reorderToIndex = (fieldNames: string[], startIndex: number, endIndex: numb
const [removed] = result.splice(startIndex, 1);
result.splice(endIndex, 0, removed);
return result.reduce(
(nameByIndex, fieldName, index) => {
nameByIndex[fieldName] = index;
return nameByIndex;
},
{} as Record<string, number>
);
return result.reduce<Record<string, number>>((nameByIndex, fieldName, index) => {
nameByIndex[fieldName] = index;
return nameByIndex;
}, {});
};
const orderFieldNamesByIndex = (fieldNames: string[], indexByName: Record<string, number> = {}): string[] => {

View File

@ -23,7 +23,7 @@ export const SortByTransformerEditor = ({ input, options, onChange }: Transforme
[onChange, options]
);
const sorts = options.sort?.length ? options.sort : [{} as SortByField];
const sorts: SortByField[] = options.sort?.length ? options.sort : [{} as SortByField];
return (
<div>

View File

@ -135,7 +135,7 @@ export const configMapHandlers: FieldToConfigMapHandler[] = [
{
key: 'displayName',
name: 'Display name',
processor: (value: any) => value.toString(),
processor: (value) => value.toString(),
},
{
key: 'color',
@ -247,7 +247,7 @@ export function getConfigMapHandlersIndex() {
return configMapHandlersIndex;
}
function toNumericOrUndefined(value: any) {
function toNumericOrUndefined(value: unknown) {
const numeric = anyToNumber(value);
if (isNaN(numeric)) {

View File

@ -28,9 +28,9 @@ const fieldNamePickerSettings: StandardEditorsRegistryItem<string, FieldNamePick
editor: () => null,
};
const fieldLookupSettings: StandardEditorsRegistryItem<string, GazetteerPathEditorConfigSettings> = {
const fieldLookupSettings = {
settings: {},
} as any;
} as StandardEditorsRegistryItem<string, GazetteerPathEditorConfigSettings>;
export const FieldLookupTransformerEditor = ({ input, options, onChange }: TransformerUIProps<FieldLookupOptions>) => {
const onPickLookupField = useCallback(
@ -60,7 +60,7 @@ export const FieldLookupTransformerEditor = ({ input, options, onChange }: Trans
context={{ data: input }}
value={options?.lookupField ?? ''}
onChange={onPickLookupField}
item={fieldNamePickerSettings as any}
item={fieldNamePickerSettings}
/>
</InlineField>
</InlineFieldRow>

View File

@ -11,7 +11,7 @@ import {
TransformerUIProps,
TransformerCategory,
} from '@grafana/data';
import { FrameGeometrySource, FrameGeometrySourceMode } from '@grafana/schema';
import { FrameGeometrySourceMode } from '@grafana/schema';
import { useTheme2 } from '@grafana/ui';
import { addLocationFields } from 'app/features/geo/editor/locationEditor';
@ -90,10 +90,9 @@ const supplier = (
category: ['Source'],
path: 'source',
build: (b, c) => {
const loc = (options.source ?? {}) as FrameGeometrySource;
if (!loc.mode) {
loc.mode = FrameGeometrySourceMode.Auto;
}
const loc = options.source ?? {
mode: FrameGeometrySourceMode.Auto,
};
addLocationFields('Point', '', b, loc);
},
});
@ -102,10 +101,9 @@ const supplier = (
category: ['Target'],
path: 'modify',
build: (b, c) => {
const loc = (options.modify?.target ?? {}) as FrameGeometrySource;
if (!loc.mode) {
loc.mode = FrameGeometrySourceMode.Auto;
}
const loc = options.modify?.target ?? {
mode: FrameGeometrySourceMode.Auto,
};
addLocationFields('Point', 'target.', b, loc);
},
});

View File

@ -31,8 +31,8 @@ export function getTransformerOptionPane<T = any>(
};
const access: NestedValueAccess = {
getValue: (path: string) => lodashGet(props.options, path),
onChange: (path: string, value: any) => {
getValue: (path) => lodashGet(props.options, path),
onChange: (path, value) => {
props.onChange(setOptionImmutably(props.options as any, path, value));
},
};

View File

@ -41,7 +41,7 @@ export function calculateBearings(values: Array<Geometry | undefined>): number[]
export function getCenterPoint(geo: Geometry): number[] {
if (geo instanceof Point) {
return (geo as Point).getCoordinates();
return geo.getCoordinates();
}
return getCenter(geo.getExtent());
}

View File

@ -9,20 +9,17 @@ export function useAllFieldNamesFromDataFrames(input: DataFrame[]): string[] {
}
return Object.keys(
input.reduce(
(names, frame) => {
if (!frame || !Array.isArray(frame.fields)) {
return names;
}
input.reduce<Record<string, boolean>>((names, frame) => {
if (!frame || !Array.isArray(frame.fields)) {
return names;
}
return frame.fields.reduce((names, field) => {
const t = getFieldDisplayName(field, frame, input);
names[t] = true;
return names;
}, names);
},
{} as Record<string, boolean>
)
return frame.fields.reduce((names, field) => {
const t = getFieldDisplayName(field, frame, input);
names[t] = true;
return names;
}, names);
}, {})
);
}, [input]);
}

View File

@ -52,7 +52,7 @@ const sharedReducerSlice = createSlice({
instanceState.state = LoadingState.Done;
instanceState.error = null;
},
variableStateFailed: (state: VariablesState, action: PayloadAction<VariablePayload<{ error: any }>>) => {
variableStateFailed: (state: VariablesState, action: PayloadAction<VariablePayload<{ error: unknown }>>) => {
const instanceState = getInstanceState(state, action.payload.id);
if (!instanceState) {
// we might have cancelled a batch so then this state has been removed

View File

@ -2,13 +2,13 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { getInstanceState } from '../state/selectors';
import { initialVariablesState, VariablePayload, VariablesState } from '../state/types';
import { initialVariableModelState, TextBoxVariableModel, VariableOption } from '../types';
import { initialVariableModelState, TextBoxVariableModel } from '../types';
export const initialTextBoxVariableModelState: TextBoxVariableModel = {
...initialVariableModelState,
type: 'textbox',
query: '',
current: {} as VariableOption,
current: {},
options: [],
originalQuery: null,
};

View File

@ -226,7 +226,7 @@ export function findTemplateVarChanges(query: UrlQueryMap, old: UrlQueryMap): Ex
return count ? changes : undefined;
}
export function ensureStringValues(value: any | any[]): string | string[] {
export function ensureStringValues(value: unknown | unknown[]): string | string[] {
if (Array.isArray(value)) {
return value.map(String);
}

View File

@ -1,22 +0,0 @@
// Safari < 14 does not have mql.addEventListener(), but uses the old spec mql.addListener()
let oMatchMedia = window.matchMedia;
type MqlListener = (this: MediaQueryList, ev: MediaQueryListEvent) => any;
window.matchMedia = (mediaQueryString) => {
let mql = oMatchMedia(mediaQueryString);
if (!mql.addEventListener) {
// @ts-ignore
mql.addEventListener = (type: string, listener: MqlListener) => {
mql.addListener(listener);
};
// @ts-ignore
mql.removeEventListener = (type: string, listener: MqlListener) => {
mql.removeListener(listener);
};
}
return mql;
};