diff --git a/.betterer.results b/.betterer.results index bbf353f4a14..641d52d1817 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1200,10 +1200,6 @@ exports[`better eslint`] = { "packages/grafana-ui/src/components/Cascader/Cascader.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "packages/grafana-ui/src/components/Cascader/optionMappings.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"] - ], "packages/grafana-ui/src/components/ClickOutsideWrapper/ClickOutsideWrapper.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], @@ -1220,11 +1216,7 @@ exports[`better eslint`] = { "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, "Do not use any type assertions.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"] - ], - "packages/grafana-ui/src/components/DataLinks/SelectionReference.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] + [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], "packages/grafana-ui/src/components/DataSourceSettings/CustomHeadersSettings.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -1255,9 +1247,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"] ], - "packages/grafana-ui/src/components/FormattedValueDisplay/FormattedValueDisplay.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "packages/grafana-ui/src/components/Forms/FieldArray.story.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], @@ -1285,17 +1274,12 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], - "packages/grafana-ui/src/components/Graph/Graph.test.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "packages/grafana-ui/src/components/Graph/Graph.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, "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, "Unexpected any. Specify a different type.", "6"] + [0, 0, 0, "Unexpected any. Specify a different type.", "4"] ], "packages/grafana-ui/src/components/Graph/GraphContextMenu.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -1482,9 +1466,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "4"], [0, 0, 0, "Unexpected any. Specify a different type.", "5"] ], - "packages/grafana-ui/src/components/SetInterval/SetInterval.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -1637,11 +1618,10 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "packages/grafana-ui/src/components/VizRepeater/VizRepeater.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], + [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.", "3"] ], "packages/grafana-ui/src/components/VizTooltip/VizTooltip.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -2578,20 +2558,10 @@ exports[`better eslint`] = { "public/app/core/components/OptionsUI/strings.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/core/components/PageHeader/PageHeader.test.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] - ], "public/app/core/components/PanelTypeFilter/PanelTypeFilter.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], - "public/app/core/components/PermissionList/DisabledPermissionListItem.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], - "public/app/core/components/RolePicker/RolePickerMenu.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/core/components/Select/ReadonlyFolderPicker/api.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -2600,9 +2570,6 @@ exports[`better eslint`] = { "public/app/core/components/Select/SortPicker.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/core/components/TagFilter/TagBadge.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/core/components/TagFilter/TagFilter.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -2619,9 +2586,7 @@ exports[`better eslint`] = { ], "public/app/core/components/TagFilter/TagValue.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, "Unexpected any. Specify a different type.", "1"] ], "public/app/core/components/connectWithCleanUp.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -2661,22 +2626,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/core/navigation/parseKeyValue.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.", "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"] - ], "public/app/core/navigation/patch/interceptLinkClicks.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"] @@ -2699,9 +2648,6 @@ exports[`better eslint`] = { "public/app/core/reducers/appNotification.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/core/reducers/navModel.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/core/reducers/processsAclItems.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], @@ -2717,9 +2663,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/core/services/ModalManager.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/core/services/PreferencesService.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] @@ -2784,10 +2727,6 @@ exports[`better eslint`] = { "public/app/core/services/echo/backends/sentry/transports/EchoSrvTransport.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/core/services/keybindingSrv.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] - ], "public/app/core/services/search_srv.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -2799,10 +2738,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "7"], [0, 0, 0, "Unexpected any. Specify a different type.", "8"] ], - "public/app/core/services/withFocusedPanelId.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"] - ], "public/app/core/specs/TableModel.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], @@ -2844,9 +2779,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "5"], [0, 0, 0, "Unexpected any. Specify a different type.", "6"] ], - "public/app/core/store.ts:5381": [ - [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"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -2989,28 +2921,15 @@ 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/admin/AdminListOrgsPage.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], - "public/app/features/admin/AdminSettings.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/admin/OrgRolePicker.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/admin/UserListAdminPage.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/admin/UserProfile.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/features/admin/ldap/LdapPage.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/features/alerting/AlertRuleList.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/AlertTab.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] @@ -3155,8 +3074,7 @@ 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, "Unexpected any. Specify a different type.", "4"] + [0, 0, 0, "Unexpected any. Specify a different type.", "3"] ], "public/app/features/alerting/unified/RuleEditor.test.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -3172,9 +3090,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/api/buildInfo.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/alerting/unified/api/ruler.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"] @@ -3630,10 +3545,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/dashboard/components/ShareModal/ShareEmbed.test.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] - ], "public/app/features/dashboard/components/ShareModal/ShareExport.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], diff --git a/packages/grafana-ui/src/components/Cascader/optionMappings.ts b/packages/grafana-ui/src/components/Cascader/optionMappings.ts index 6d490609d70..d437d0bfe83 100644 --- a/packages/grafana-ui/src/components/Cascader/optionMappings.ts +++ b/packages/grafana-ui/src/components/Cascader/optionMappings.ts @@ -29,6 +29,6 @@ const fromRCOptions = (options: RCCascaderOption[]): CascaderOption[] => { const fromRCOption = (option: RCCascaderOption): CascaderOption => { return { value: option.value ?? '', - label: option.label as unknown as string, + label: option.label, }; }; diff --git a/packages/grafana-ui/src/components/DataLinks/DataLinkInput.tsx b/packages/grafana-ui/src/components/DataLinks/DataLinkInput.tsx index 324fc049624..127bf984819 100644 --- a/packages/grafana-ui/src/components/DataLinks/DataLinkInput.tsx +++ b/packages/grafana-ui/src/components/DataLinks/DataLinkInput.tsx @@ -1,6 +1,6 @@ import { css, cx } from '@emotion/css'; import Prism, { Grammar, LanguageMap } from 'prismjs'; -import React, { memo, RefObject, useEffect, useMemo, useRef, useState } from 'react'; +import React, { memo, useEffect, useMemo, useRef, useState } from 'react'; import { Popper as ReactPopper } from 'react-popper'; import usePrevious from 'react-use/lib/usePrevious'; import { Value } from 'slate'; @@ -74,7 +74,7 @@ const getStyles = (theme: GrafanaTheme2) => ({ // was used and changes to different state were propagated here. export const DataLinkInput: React.FC = memo( ({ value, onChange, suggestions, placeholder = 'http://your-grafana.com/d/000000010/annotations' }) => { - const editorRef = useRef() as RefObject; + const editorRef = useRef(null); const styles = useStyles2(getStyles); const [showingSuggestions, setShowingSuggestions] = useState(false); const [suggestionsIndex, setSuggestionsIndex] = useState(0); diff --git a/packages/grafana-ui/src/components/DataLinks/SelectionReference.ts b/packages/grafana-ui/src/components/DataLinks/SelectionReference.ts index 725ec3f2ce4..43a993d60aa 100644 --- a/packages/grafana-ui/src/components/DataLinks/SelectionReference.ts +++ b/packages/grafana-ui/src/components/DataLinks/SelectionReference.ts @@ -10,14 +10,18 @@ export class SelectionReference implements VirtualElement { return rect; } - return { + const fallbackDOMRect: DOMRect = { top: 0, left: 0, bottom: 0, right: 0, width: 0, height: 0, - } as DOMRect; + x: 0, + y: 0, + toJSON: () => {}, + }; + return fallbackDOMRect; } get clientWidth() { diff --git a/packages/grafana-ui/src/components/FormattedValueDisplay/FormattedValueDisplay.tsx b/packages/grafana-ui/src/components/FormattedValueDisplay/FormattedValueDisplay.tsx index 17a074d0f8c..a34c6a7d893 100644 --- a/packages/grafana-ui/src/components/FormattedValueDisplay/FormattedValueDisplay.tsx +++ b/packages/grafana-ui/src/components/FormattedValueDisplay/FormattedValueDisplay.tsx @@ -23,8 +23,8 @@ export const FormattedValueDisplay: FC = ({ value, className, style, ...h const hasSuffix = (value.suffix ?? '').length > 0; let suffixStyle; - if (style && style.fontSize) { - const fontSize = style?.fontSize as number; + if (style && style.fontSize && typeof style.fontSize === 'number') { + const fontSize = style.fontSize; const reductionFactor = fontSizeReductionFactor(fontSize); suffixStyle = { fontSize: fontSize * reductionFactor }; } diff --git a/packages/grafana-ui/src/components/Graph/Graph.test.tsx b/packages/grafana-ui/src/components/Graph/Graph.test.tsx index 4da05ef73dd..36183bba34c 100644 --- a/packages/grafana-ui/src/components/Graph/Graph.test.tsx +++ b/packages/grafana-ui/src/components/Graph/Graph.test.tsx @@ -89,9 +89,10 @@ const mockGraphProps = (multiSeries = false) => { }; }; -(window as any).ResizeObserver = class ResizeObserver { +window.ResizeObserver = class ResizeObserver { constructor() {} observe() {} + unobserve() {} disconnect() {} }; diff --git a/packages/grafana-ui/src/components/Graph/Graph.tsx b/packages/grafana-ui/src/components/Graph/Graph.tsx index 3a7d3aea487..4c08ef35603 100644 --- a/packages/grafana-ui/src/components/Graph/Graph.tsx +++ b/packages/grafana-ui/src/components/Graph/Graph.tsx @@ -117,8 +117,9 @@ export class Graph extends PureComponent { return uniqBy( series.map((s) => { const index = s.yAxis ? s.yAxis.index : 1; - const min = s.yAxis && !isNaN(s.yAxis.min as number) ? s.yAxis.min : null; - const tickDecimals = s.yAxis && !isNaN(s.yAxis.tickDecimals as number) ? s.yAxis.tickDecimals : null; + const min = s.yAxis && s.yAxis.min && !isNaN(s.yAxis.min) ? s.yAxis.min : null; + const tickDecimals = + s.yAxis && s.yAxis.tickDecimals && !isNaN(s.yAxis.tickDecimals) ? s.yAxis.tickDecimals : null; return { show: true, index, diff --git a/packages/grafana-ui/src/components/SetInterval/SetInterval.tsx b/packages/grafana-ui/src/components/SetInterval/SetInterval.tsx index a2066fb4a07..2df449a4edf 100644 --- a/packages/grafana-ui/src/components/SetInterval/SetInterval.tsx +++ b/packages/grafana-ui/src/components/SetInterval/SetInterval.tsx @@ -15,7 +15,7 @@ export function getIntervalFromString(strInterval: string): SelectableValue any; // TODO + func: () => unknown; loading: boolean; interval: string; } diff --git a/packages/grafana-ui/src/components/VizRepeater/VizRepeater.tsx b/packages/grafana-ui/src/components/VizRepeater/VizRepeater.tsx index 544e8c1515f..7fb1cc112dc 100644 --- a/packages/grafana-ui/src/components/VizRepeater/VizRepeater.tsx +++ b/packages/grafana-ui/src/components/VizRepeater/VizRepeater.tsx @@ -19,7 +19,7 @@ interface Props { renderValue: (props: VizRepeaterRenderValueProps) => JSX.Element; height: number; width: number; - source: any; // If this changes, new values will be requested + source: unknown; // If this changes, new values will be requested getValues: () => V[]; renderCounter: number; // force update of values & render orientation: VizOrientation; diff --git a/public/app/core/components/PageHeader/PageHeader.test.tsx b/public/app/core/components/PageHeader/PageHeader.test.tsx index 3e5af5ee1f9..e7c53a234af 100644 --- a/public/app/core/components/PageHeader/PageHeader.test.tsx +++ b/public/app/core/components/PageHeader/PageHeader.test.tsx @@ -1,12 +1,14 @@ import { render, screen } from '@testing-library/react'; import React from 'react'; +import { NavModelItem } from '@grafana/data'; + import { PageHeader } from './PageHeader'; describe('PageHeader', () => { describe('when the nav tree has a node with a title', () => { it('should render the title', async () => { - const nav = { + const nav: NavModelItem = { icon: 'folder-open', id: 'node', subTitle: 'node subtitle', @@ -14,7 +16,7 @@ describe('PageHeader', () => { text: 'node', }; - render(); + render(); expect(screen.getByRole('heading', { name: 'node' })).toBeInTheDocument(); }); @@ -22,7 +24,7 @@ describe('PageHeader', () => { describe('when the nav tree has a node with breadcrumbs and a title', () => { it('should render the title with breadcrumbs first and then title last', async () => { - const nav = { + const nav: NavModelItem = { icon: 'folder-open', id: 'child', subTitle: 'child subtitle', @@ -31,7 +33,7 @@ describe('PageHeader', () => { breadcrumbs: [{ title: 'Parent', url: 'parentUrl' }], }; - render(); + render(); expect(screen.getByRole('heading', { name: 'Parent / child' })).toBeInTheDocument(); expect(screen.getByRole('link', { name: 'Parent' })).toBeInTheDocument(); diff --git a/public/app/core/components/PermissionList/DisabledPermissionListItem.tsx b/public/app/core/components/PermissionList/DisabledPermissionListItem.tsx index cd6b0ed68f1..ae0fd53fe35 100644 --- a/public/app/core/components/PermissionList/DisabledPermissionListItem.tsx +++ b/public/app/core/components/PermissionList/DisabledPermissionListItem.tsx @@ -7,7 +7,7 @@ export interface Props { item: DashboardAcl; } -export default class DisabledPermissionListItem extends Component { +export default class DisabledPermissionListItem extends Component { render() { const { item } = this.props; const currentPermissionLevel = dashboardPermissionLevels.find((dp) => dp.value === item.permission); diff --git a/public/app/core/components/RolePicker/RolePickerMenu.tsx b/public/app/core/components/RolePicker/RolePickerMenu.tsx index 105c2d31614..16b6236c8e0 100644 --- a/public/app/core/components/RolePicker/RolePickerMenu.tsx +++ b/public/app/core/components/RolePicker/RolePickerMenu.tsx @@ -413,7 +413,7 @@ export const RolePickerSubMenu = ({ ); }; -interface RoleMenuOptionProps { +interface RoleMenuOptionProps { data: Role; onChange: (value: Role) => void; isSelected?: boolean; @@ -422,7 +422,7 @@ interface RoleMenuOptionProps { hideDescription?: boolean; } -export const RoleMenuOption = React.forwardRef>>( +export const RoleMenuOption = React.forwardRef>( ({ data, isFocused, isSelected, disabled, onChange, hideDescription }, ref) => { const theme = useTheme2(); const styles = getSelectStyles(theme); diff --git a/public/app/core/components/TagFilter/TagBadge.tsx b/public/app/core/components/TagFilter/TagBadge.tsx index 8d9c0bcadb7..8d4c84502d2 100644 --- a/public/app/core/components/TagFilter/TagBadge.tsx +++ b/public/app/core/components/TagFilter/TagBadge.tsx @@ -9,7 +9,7 @@ export interface Props { onClick?: React.MouseEventHandler; } -export class TagBadge extends React.Component { +export class TagBadge extends React.Component { constructor(props: Props) { super(props); } diff --git a/public/app/core/components/TagFilter/TagValue.tsx b/public/app/core/components/TagFilter/TagValue.tsx index a7e2bc9ae5c..e481ebf9531 100644 --- a/public/app/core/components/TagFilter/TagValue.tsx +++ b/public/app/core/components/TagFilter/TagValue.tsx @@ -4,12 +4,12 @@ import { TagBadge } from './TagBadge'; export interface Props { value: any; - className: any; + className: string; onClick: React.MouseEventHandler; - onRemove: any; + onRemove: (value: any, event: React.MouseEvent) => void; } -export class TagValue extends React.Component { +export class TagValue extends React.Component { constructor(props: Props) { super(props); this.onClick = this.onClick.bind(this); diff --git a/public/app/core/navigation/parseKeyValue.ts b/public/app/core/navigation/parseKeyValue.ts deleted file mode 100644 index 4beca488c9a..00000000000 --- a/public/app/core/navigation/parseKeyValue.ts +++ /dev/null @@ -1,161 +0,0 @@ -// tslint:disable -// Most of this file is just a copy of some content from -// https://github.com/angular/angular.js/blob/937fb891fa4fcf79e9fa02f8e0d517593e781077/src/Angular.js -// Long term this code should be refactored to tru-type-script ;) -// tslint disabled on purpose - -const getPrototypeOf = Object.getPrototypeOf; -const toString = Object.prototype.toString; -const hasOwnProperty = Object.prototype.hasOwnProperty; - -let jqLite: any; - -export function isArray(arr: any) { - return Array.isArray(arr) || arr instanceof Array; -} - -export function isError(value: any) { - const tag = toString.call(value); - switch (tag) { - case '[object Error]': - return true; - case '[object Exception]': - return true; - case '[object DOMException]': - return true; - default: - return value instanceof Error; - } -} -export function isDate(value: any) { - return toString.call(value) === '[object Date]'; -} -export function isNumber(value: any) { - return typeof value === 'number'; -} - -export function isString(value: any) { - return typeof value === 'string'; -} -export function isBlankObject(value: any) { - return value !== null && typeof value === 'object' && !getPrototypeOf(value); -} -export function isObject(value: any) { - // http://jsperf.com/isobject4 - return value !== null && typeof value === 'object'; -} - -export function isWindow(obj: { window: any }) { - return obj && obj.window === obj; -} - -export function isArrayLike(obj: any) { - // `null`, `undefined` and `window` are not array-like - if (obj == null || isWindow(obj)) { - return false; - } - - // arrays, strings and jQuery/jqLite objects are array like - // * jqLite is either the jQuery or jqLite constructor function - // * we have to check the existence of jqLite first as this method is called - // via the forEach method when constructing the jqLite object in the first place - if (isArray(obj) || isString(obj) || (jqLite && obj instanceof jqLite)) { - return true; - } - - // Support: iOS 8.2 (not reproducible in simulator) - // "length" in obj used to prevent JIT error (gh-11508) - const length = 'length' in Object(obj) && obj.length; - - // NodeList objects (with `item` method) and - // other objects with suitable length characteristics are array-like - return isNumber(length) && ((length >= 0 && length - 1 in obj) || typeof obj.item === 'function'); -} -export function isFunction(value: any) { - return typeof value === 'function'; -} - -export function forEach(obj: any, iterator: any, context?: any) { - let key, length; - if (obj) { - if (isFunction(obj)) { - for (key in obj) { - if (key !== 'prototype' && key !== 'length' && key !== 'name' && obj.hasOwnProperty(key)) { - iterator.call(context, obj[key], key, obj); - } - } - } else if (isArray(obj) || isArrayLike(obj)) { - const isPrimitive = typeof obj !== 'object'; - for (key = 0, length = obj.length; key < length; key++) { - if (isPrimitive || key in obj) { - iterator.call(context, obj[key], key, obj); - } - } - } else if (obj.forEach && obj.forEach !== forEach) { - obj.forEach(iterator, context, obj); - } else if (isBlankObject(obj)) { - // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty - for (key in obj) { - iterator.call(context, obj[key], key, obj); - } - } else if (typeof obj.hasOwnProperty === 'function') { - // Slow path for objects inheriting Object.prototype, hasOwnProperty check needed - for (key in obj) { - if (obj.hasOwnProperty(key)) { - iterator.call(context, obj[key], key, obj); - } - } - } else { - // Slow path for objects which do not have a method `hasOwnProperty` - for (key in obj) { - if (hasOwnProperty.call(obj, key)) { - iterator.call(context, obj[key], key, obj); - } - } - } - } - return obj; -} -export function tryDecodeURIComponent(value: string): string { - try { - return decodeURIComponent(value); - } catch (e) { - // Ignore any invalid uri component. - return ''; - } -} - -function parseKeyValue(keyValue: string | null) { - const obj = {}; - forEach((keyValue || '').split('&'), function (keyValue: string) { - let splitPoint, key, val; - if (keyValue) { - key = keyValue = keyValue.replace(/\+/g, '%20'); - splitPoint = keyValue.indexOf('='); - if (splitPoint !== -1) { - key = keyValue.substring(0, splitPoint); - val = keyValue.substring(splitPoint + 1); - } - key = tryDecodeURIComponent(key); - if (key) { - val = val !== undefined ? tryDecodeURIComponent(val) : true; - if (!hasOwnProperty.call(obj, key)) { - // @ts-ignore - obj[key] = val; - // @ts-ignore - } else if (isArray(obj[key])) { - // @ts-ignore - obj[key].push(val); - } else { - // @ts-ignore - obj[key] = [obj[key], val]; - } - } - } - }); - return obj; -} - -export default parseKeyValue; - -// tslint:enable diff --git a/public/app/core/reducers/navModel.ts b/public/app/core/reducers/navModel.ts index e0b9a2658f7..aed934b7931 100644 --- a/public/app/core/reducers/navModel.ts +++ b/public/app/core/reducers/navModel.ts @@ -8,7 +8,7 @@ export const HOME_NAV_ID = 'home'; export function buildInitialState(): NavIndex { const navIndex: NavIndex = {}; - const rootNodes = cloneDeep(config.bootData.navTree as NavModelItem[]); + const rootNodes = cloneDeep(config.bootData.navTree); const homeNav = rootNodes.find((node) => node.id === HOME_NAV_ID); // set home as parent for the rootNodes diff --git a/public/app/core/services/ModalManager.ts b/public/app/core/services/ModalManager.ts index a84880998d9..ce7f3b02d7e 100644 --- a/public/app/core/services/ModalManager.ts +++ b/public/app/core/services/ModalManager.ts @@ -7,7 +7,12 @@ import { ConfirmModal, ConfirmModalProps } from '@grafana/ui'; import appEvents from 'app/core/app_events'; import { copyPanel } from 'app/features/dashboard/utils/panel'; -import { ShowConfirmModalEvent, ShowConfirmModalPayload, ShowModalReactEvent } from '../../types/events'; +import { + ShowConfirmModalEvent, + ShowConfirmModalPayload, + ShowModalReactEvent, + ShowModalReactPayload, +} from '../../types/events'; import { AngularModalProxy } from '../components/modals/AngularModalProxy'; import { provideTheme } from '../utils/ConfigProvider'; @@ -21,7 +26,7 @@ export class ModalManager { appEvents.subscribe(CopyPanelEvent, (e) => copyPanel(e.payload)); } - showModalReact(options: any) { + showModalReact(options: ShowModalReactPayload) { const { component, props } = options; const modalProps = { component, diff --git a/public/app/core/services/keybindingSrv.ts b/public/app/core/services/keybindingSrv.ts index 86fda1ed86f..9706221a0e7 100644 --- a/public/app/core/services/keybindingSrv.ts +++ b/public/app/core/services/keybindingSrv.ts @@ -58,7 +58,7 @@ export class KeybindingSrv { } globalEsc() { - const anyDoc = document as any; + const anyDoc = document; const activeElement = anyDoc.activeElement; // typehead needs to handle it @@ -68,13 +68,13 @@ export class KeybindingSrv { } // second check if we are in an input we can blur - if (activeElement && activeElement.blur) { + if (activeElement && activeElement instanceof HTMLElement) { if ( activeElement.nodeName === 'INPUT' || activeElement.nodeName === 'TEXTAREA' || activeElement.hasAttribute('data-slate-editor') ) { - anyDoc.activeElement.blur(); + activeElement.blur(); return; } } diff --git a/public/app/core/services/withFocusedPanelId.ts b/public/app/core/services/withFocusedPanelId.ts index 76713c9c42d..857144ee706 100644 --- a/public/app/core/services/withFocusedPanelId.ts +++ b/public/app/core/services/withFocusedPanelId.ts @@ -3,8 +3,8 @@ export function withFocusedPanel(fn: (panelId: number) => void) { const elements = document.querySelectorAll(':hover'); for (let i = elements.length - 1; i > 0; i--) { - const element = elements[i] as unknown as HTMLElement; - if (element.dataset?.panelid) { + const element = elements[i]; + if (element instanceof HTMLElement && element.dataset?.panelid) { fn(parseInt(element.dataset?.panelid, 10)); } } diff --git a/public/app/core/store.ts b/public/app/core/store.ts index 66891035406..28587a7d428 100644 --- a/public/app/core/store.ts +++ b/public/app/core/store.ts @@ -32,7 +32,7 @@ export class Store { } /* Returns true when successfully stored, throws error if not successfully stored */ - setObject(key: string, value: any) { + setObject(key: string, value: unknown) { let json; try { json = JSON.stringify(value); diff --git a/public/app/features/admin/AdminListOrgsPage.tsx b/public/app/features/admin/AdminListOrgsPage.tsx index da5fe17d823..486c6a37d1f 100644 --- a/public/app/features/admin/AdminListOrgsPage.tsx +++ b/public/app/features/admin/AdminListOrgsPage.tsx @@ -1,7 +1,7 @@ import React, { useEffect } from 'react'; import useAsyncFn from 'react-use/lib/useAsyncFn'; -import { getBackendSrv } from '@grafana/runtime'; +import { getBackendSrv, isFetchError } from '@grafana/runtime'; import { LinkButton } from '@grafana/ui'; import { Page } from 'app/core/components/Page/Page'; import { contextSrv } from 'app/core/services/context_srv'; @@ -17,8 +17,8 @@ const getOrgs = async () => { return await getBackendSrv().get('/api/orgs'); }; -const getErrorMessage = (error: any) => { - return error?.data?.message || 'An unexpected error happened.'; +const getErrorMessage = (error: Error) => { + return isFetchError(error) ? error?.data?.message : 'An unexpected error happened.'; }; export default function AdminListOrgsPages() { diff --git a/public/app/features/admin/AdminSettings.tsx b/public/app/features/admin/AdminSettings.tsx index e099049f8d8..656709772be 100644 --- a/public/app/features/admin/AdminSettings.tsx +++ b/public/app/features/admin/AdminSettings.tsx @@ -7,10 +7,7 @@ import { Page } from 'app/core/components/Page/Page'; type Settings = { [key: string]: { [key: string]: string } }; function AdminSettings() { - const { loading, value: settings } = useAsync( - () => getBackendSrv().get('/api/admin/settings') as Promise, - [] - ); + const { loading, value: settings } = useAsync(() => getBackendSrv().get('/api/admin/settings'), []); return ( diff --git a/public/app/features/admin/UserListAdminPage.tsx b/public/app/features/admin/UserListAdminPage.tsx index a4cee991c77..308c6841427 100644 --- a/public/app/features/admin/UserListAdminPage.tsx +++ b/public/app/features/admin/UserListAdminPage.tsx @@ -24,7 +24,7 @@ import { changeFilter, changePage, changeQuery, fetchUsers } from './state/actio export interface FilterProps { filters: UserFilter[]; - onChange: (filter: any) => void; + onChange: (filter: UserFilter) => void; className?: string; } const extraFilters: Array> = []; diff --git a/public/app/features/alerting/AlertRuleList.tsx b/public/app/features/alerting/AlertRuleList.tsx index 12f07e39a48..55dc35d0ca2 100644 --- a/public/app/features/alerting/AlertRuleList.tsx +++ b/public/app/features/alerting/AlertRuleList.tsx @@ -130,10 +130,10 @@ export class AlertRuleListUnconnected extends PureComponent { {alertRules.map((rule) => { return ( this.onTogglePause(rule as AlertRule)} + onTogglePause={() => this.onTogglePause(rule)} /> ); })} diff --git a/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx b/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx index 935e95fbe61..4fc0d82a73f 100644 --- a/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx +++ b/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx @@ -255,7 +255,7 @@ describe('PanelAlertTabContent', () => { }); it('Will take into account datasource minInterval', async () => { - (getDatasourceSrv() as any as MockDataSourceSrv).datasources[dataSources.prometheus.uid].interval = '7m'; + (getDatasourceSrv() as unknown as MockDataSourceSrv).datasources[dataSources.prometheus.uid].interval = '7m'; await renderAlertTabContent( dashboard, diff --git a/public/app/features/alerting/unified/api/buildInfo.ts b/public/app/features/alerting/unified/api/buildInfo.ts index 5cf40832d0f..25673c4c0f4 100644 --- a/public/app/features/alerting/unified/api/buildInfo.ts +++ b/public/app/features/alerting/unified/api/buildInfo.ts @@ -190,12 +190,10 @@ async function hasRulerSupport(dataSourceName: string) { } } // there errors indicate that the ruler API might be disabled or not supported for Cortex -function errorIndicatesMissingRulerSupport(error: any) { - return ( - (isFetchError(error) && - (error.data.message?.includes('GetRuleGroup unsupported in rule local store') || // "local" rule storage - error.data.message?.includes('page not found'))) || // ruler api disabled - error.message?.includes('404 from rules config endpoint') || // ruler api disabled - error.data.message?.includes(RULER_NOT_SUPPORTED_MSG) // ruler api not supported - ); +function errorIndicatesMissingRulerSupport(error: unknown) { + return isFetchError(error) + ? error.data.message?.includes('GetRuleGroup unsupported in rule local store') || // "local" rule storage + error.data.message?.includes('page not found') || // ruler api disabled + error.data.message?.includes(RULER_NOT_SUPPORTED_MSG) // ruler api not supported + : error instanceof Error && error.message?.includes('404 from rules config endpoint'); // ruler api disabled } diff --git a/public/app/features/dashboard/components/ShareModal/ShareEmbed.test.tsx b/public/app/features/dashboard/components/ShareModal/ShareEmbed.test.tsx index d64617b0f49..98a7f1bd03d 100644 --- a/public/app/features/dashboard/components/ShareModal/ShareEmbed.test.tsx +++ b/public/app/features/dashboard/components/ShareModal/ShareEmbed.test.tsx @@ -40,7 +40,7 @@ function mockLocationHref(href: string) { // @ts-ignore delete window.location; - (window as any).location = { + window.location = { ...location, href, origin: new URL(href).origin, @@ -60,7 +60,7 @@ describe('ShareEmbed', () => { user: { orgId: 1, }, - } as any; + } as BootData; }); afterAll(() => {