Chore: Improve some types (#64675)

* some type fixes

* few more

* more type fixes

* fix the majority of (window as any) calls

* don't make new variable for event

* few more

* MOAR
This commit is contained in:
Ashley Harrison
2023-03-14 09:51:44 +00:00
committed by GitHub
parent aade4b0bd2
commit 53186c14a4
73 changed files with 256 additions and 436 deletions

View File

@@ -21,7 +21,7 @@ import {
import { LibraryElementDTO } from '../../../library-panels/types';
import { DashboardModel, PanelModel } from '../../state';
export type PanelPluginInfo = { id: any; defaults: { gridPos: { w: any; h: any }; title: any } };
export type PanelPluginInfo = { id: number; defaults: { gridPos: { w: number; h: number }; title: string } };
export interface OwnProps {
panel: PanelModel;
@@ -88,7 +88,7 @@ export const AddPanelWidgetUnconnected = ({ panel, dashboard }: Props) => {
const onPasteCopiedPanel = (panelPluginInfo: PanelPluginInfo) => {
const { gridPos } = panel;
const newPanel: any = {
const newPanel = {
type: panelPluginInfo.id,
title: 'Panel Title',
gridPos: {
@@ -124,7 +124,7 @@ export const AddPanelWidgetUnconnected = ({ panel, dashboard }: Props) => {
};
const onCreateNewRow = () => {
const newRow: any = {
const newRow = {
type: 'row',
title: 'Row title',
gridPos: { x: 0, y: 0 },

View File

@@ -13,7 +13,7 @@ export interface OptionsPaneItemProps {
value?: any;
description?: string;
popularRank?: number;
render: () => React.ReactNode;
render: () => React.ReactElement;
skipField?: boolean;
showIf?: () => boolean;
overrides?: OptionPaneItemOverrideInfo[];
@@ -94,7 +94,7 @@ export class OptionsPaneItemDescriptor {
key={key}
aria-label={selectors.components.PanelEditor.OptionsPane.fieldLabel(key)}
>
{render() as React.ReactElement}
{render()}
</Field>
);
}

View File

@@ -167,13 +167,13 @@ export class PanelEditorUnconnected extends PureComponent<Props> {
});
};
onPanelOptionsChanged = (options: any) => {
onPanelOptionsChanged = (options: PanelModel['options']) => {
// we do not need to trigger force update here as the function call below
// fires PanelOptionsChangedEvent which we subscribe to above
this.props.panel.updateOptions(options);
};
onPanelConfigChanged = (configKey: keyof PanelModel, value: any) => {
onPanelConfigChanged = (configKey: keyof PanelModel, value: unknown) => {
this.props.panel.setProperty(configKey, value);
this.props.panel.render();
this.forceUpdate();

View File

@@ -155,7 +155,7 @@ export function getFieldOverrideCategories(
continue;
}
const onPropertyChange = (value: any) => {
const onPropertyChange = (value: DynamicConfigValue) => {
override.properties[propIdx].value = value;
onOverrideChange(idx, override);
};

View File

@@ -82,8 +82,8 @@ export function getVisualizationOptions(props: OptionPaneRenderProps): OptionsPa
};
const access: NestedValueAccess = {
getValue: (path: string) => lodashGet(currentOptions, path),
onChange: (path: string, value: any) => {
getValue: (path) => lodashGet(currentOptions, path),
onChange: (path, value) => {
const newOptions = setOptionImmutably(currentOptions, path, value);
onPanelOptionsChanged(newOptions);
},

View File

@@ -56,8 +56,8 @@ export interface OptionPaneRenderProps {
data?: PanelData;
dashboard: DashboardModel;
instanceState: any;
onPanelConfigChange: (configKey: keyof PanelModel, value: any) => void;
onPanelOptionsChanged: (options: any) => void;
onPanelConfigChange: (configKey: keyof PanelModel, value: unknown) => void;
onPanelOptionsChanged: (options: PanelModel['options']) => void;
onFieldConfigsChange: (config: FieldConfigSource) => void;
}

View File

@@ -18,7 +18,7 @@ export const RepeatRowSelect: FC<Props> = ({ repeat, onChange, id }) => {
});
const variableOptions = useMemo(() => {
const options = variables.map((item: any) => {
const options: Array<SelectableValue<string | null>> = variables.map((item) => {
return { label: item.name, value: item.name };
});

View File

@@ -43,16 +43,6 @@ function mockLocationHref(href: string) {
};
}
function setUTCTimeZone() {
(window as any).Intl.DateTimeFormat = () => {
return {
resolvedOptions: () => {
return { timeZone: 'UTC' };
},
};
};
}
const mockUid = 'abc123';
jest.mock('@grafana/runtime', () => {
const original = jest.requireActual('@grafana/runtime');
@@ -80,7 +70,13 @@ describe('ShareModal', () => {
beforeEach(() => {
const defaultTimeRange = getDefaultTimeRange();
setUTCTimeZone();
jest.spyOn(window.Intl, 'DateTimeFormat').mockImplementation(() => {
return {
resolvedOptions: () => {
return { timeZone: 'UTC' };
},
} as Intl.DateTimeFormat;
});
mockLocationHref('http://server/#!/test');
config.rendererAvailable = true;
config.bootData.user.orgId = 1;

View File

@@ -95,7 +95,7 @@ export class ShareModal extends React.Component<Props, State> {
reportInteraction('grafana_dashboards_share_modal_viewed');
}
onSelectTab = (t: any) => {
onSelectTab: React.ComponentProps<typeof ModalTabsHeader>['onChangeTab'] = (t) => {
this.setState((prevState) => ({ ...prevState, activeTab: t.value }));
};

View File

@@ -121,11 +121,11 @@ export function getLocalTimeZone() {
const utcOffset = '&tz=UTC' + encodeURIComponent(dateTime().format('Z'));
// Older browser does not the internationalization API
if (!(window as any).Intl) {
if (!window.Intl) {
return utcOffset;
}
const dateFormat = (window as any).Intl.DateTimeFormat();
const dateFormat = window.Intl.DateTimeFormat();
if (!dateFormat.resolvedOptions) {
return utcOffset;
}

View File

@@ -54,7 +54,7 @@ export const jsonDiff = (lhs: any, rhs: any): Diffs => {
const sortByLineNumber = (diffs: Diff[]) => sortBy(diffs, 'startLineNumber');
const groupByPath = (diffs: Diff[]) =>
diffs.reduce<Record<string, any>>((acc, value) => {
diffs.reduce<Record<string, Diff[]>>((acc, value) => {
const groupKey: string = value.path[0];
if (!acc[groupKey]) {
acc[groupKey] = [];