From f530775e45b576fd0df1987833ed91192642f037 Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Wed, 2 Mar 2022 14:02:09 +0000 Subject: [PATCH] Chore: Remove several 'as' type assertions (#45913) --- public/app/core/components/Footer/Footer.tsx | 4 ++-- .../core/components/PageActionBar/PageActionBar.tsx | 4 ++-- .../core/components/PermissionList/AddPermission.tsx | 4 ++-- .../core/components/RolePicker/RolePickerInput.tsx | 4 ++-- public/app/core/components/Select/SortPicker.tsx | 4 ++-- .../components/SplitPaneWrapper/SplitPaneWrapper.tsx | 11 ++++------- .../app/core/history/RichHistoryLocalStorage.test.ts | 8 +++----- public/app/core/store.ts | 4 +++- public/app/features/canvas/runtime/root.tsx | 4 ++-- public/app/features/explore/state/utils.ts | 2 +- 10 files changed, 23 insertions(+), 26 deletions(-) diff --git a/public/app/core/components/Footer/Footer.tsx b/public/app/core/components/Footer/Footer.tsx index 895d0d93650..b3c045e2a37 100644 --- a/public/app/core/components/Footer/Footer.tsx +++ b/public/app/core/components/Footer/Footer.tsx @@ -5,7 +5,7 @@ import { Icon, IconName } from '@grafana/ui'; export interface FooterLink { text: string; id?: string; - icon?: string; + icon?: IconName; url?: string; target?: string; } @@ -77,7 +77,7 @@ export const Footer: FC = React.memo(() => { {links.map((link) => (
  • - {link.icon && } {link.text} + {link.icon && } {link.text}
  • ))} diff --git a/public/app/core/components/PageActionBar/PageActionBar.tsx b/public/app/core/components/PageActionBar/PageActionBar.tsx index 1c771a4e0f0..a3471875063 100644 --- a/public/app/core/components/PageActionBar/PageActionBar.tsx +++ b/public/app/core/components/PageActionBar/PageActionBar.tsx @@ -12,10 +12,10 @@ export interface Props { export default class PageActionBar extends PureComponent { render() { const { searchQuery, linkButton, setSearchQuery, target, placeholder = 'Search by name or type' } = this.props; - const linkProps = { href: linkButton?.href, disabled: linkButton?.disabled }; + const linkProps: typeof LinkButton.defaultProps = { href: linkButton?.href, disabled: linkButton?.disabled }; if (target) { - (linkProps as any).target = target; + linkProps.target = target; } return ( diff --git a/public/app/core/components/PermissionList/AddPermission.tsx b/public/app/core/components/PermissionList/AddPermission.tsx index dcdd9bb6628..3555c6ef4db 100644 --- a/public/app/core/components/PermissionList/AddPermission.tsx +++ b/public/app/core/components/PermissionList/AddPermission.tsx @@ -41,8 +41,8 @@ class AddPermissions extends Component { }; } - onTypeChanged = (item: any) => { - const type = item.value as AclTarget; + onTypeChanged = (item: SelectableValue) => { + const type = item.value; switch (type) { case AclTarget.User: diff --git a/public/app/core/components/RolePicker/RolePickerInput.tsx b/public/app/core/components/RolePicker/RolePickerInput.tsx index f0b2d52c24c..3108e2c0b2e 100644 --- a/public/app/core/components/RolePicker/RolePickerInput.tsx +++ b/public/app/core/components/RolePicker/RolePickerInput.tsx @@ -1,4 +1,4 @@ -import React, { FormEvent, HTMLProps, MutableRefObject, useEffect, useRef } from 'react'; +import React, { FormEvent, HTMLProps, useEffect, useRef } from 'react'; import { css, cx } from '@emotion/css'; import { useStyles2, getInputStyles, sharedInputStyle, styleMixins, Tooltip, Icon } from '@grafana/ui'; import { GrafanaTheme2 } from '@grafana/data'; @@ -36,7 +36,7 @@ export const RolePickerInput = ({ useEffect(() => { if (isFocused) { - (inputRef as MutableRefObject).current?.focus(); + inputRef.current?.focus(); } }); diff --git a/public/app/core/components/Select/SortPicker.tsx b/public/app/core/components/Select/SortPicker.tsx index 9ecdc6b6c60..e2f2a682939 100644 --- a/public/app/core/components/Select/SortPicker.tsx +++ b/public/app/core/components/Select/SortPicker.tsx @@ -1,6 +1,6 @@ import React, { FC } from 'react'; import { useAsync } from 'react-use'; -import { Icon, IconName, Select } from '@grafana/ui'; +import { Icon, Select } from '@grafana/ui'; import { SelectableValue } from '@grafana/data'; import { DEFAULT_SORT } from 'app/features/search/constants'; import { SearchSrv } from '../../services/search_srv'; @@ -36,7 +36,7 @@ export const SortPicker: FC = ({ onChange, value, placeholder, filter }) options={options} aria-label="Sort" placeholder={placeholder ?? `Sort (Default ${DEFAULT_SORT.label})`} - prefix={} + prefix={} /> ) : null; }; diff --git a/public/app/core/components/SplitPaneWrapper/SplitPaneWrapper.tsx b/public/app/core/components/SplitPaneWrapper/SplitPaneWrapper.tsx index 18d143e6476..4efc15bc8da 100644 --- a/public/app/core/components/SplitPaneWrapper/SplitPaneWrapper.tsx +++ b/public/app/core/components/SplitPaneWrapper/SplitPaneWrapper.tsx @@ -19,7 +19,7 @@ interface Props { } export class SplitPaneWrapper extends PureComponent { - rafToken = createRef(); + rafToken: MutableRefObject = createRef(); static defaultProps = { rightPaneVisible: true, }; @@ -36,7 +36,7 @@ export class SplitPaneWrapper extends PureComponent { if (this.rafToken.current !== undefined) { window.cancelAnimationFrame(this.rafToken.current!); } - (this.rafToken as MutableRefObject).current = window.requestAnimationFrame(() => { + this.rafToken.current = window.requestAnimationFrame(() => { this.forceUpdate(); }); }; @@ -68,8 +68,7 @@ export class SplitPaneWrapper extends PureComponent { renderHorizontalSplit() { const { leftPaneComponents, uiState } = this.props; const styles = getStyles(config.theme); - const topPaneSize = - uiState.topPaneSize >= 1 ? (uiState.topPaneSize as number) : (uiState.topPaneSize as number) * window.innerHeight; + const topPaneSize = uiState.topPaneSize >= 1 ? uiState.topPaneSize : uiState.topPaneSize * window.innerHeight; /* Guesstimate the height of the browser window minus @@ -104,9 +103,7 @@ export class SplitPaneWrapper extends PureComponent { // Need to handle when width is relative. ie a percentage of the viewport const rightPaneSize = - uiState.rightPaneSize <= 1 - ? (uiState.rightPaneSize as number) * window.innerWidth - : (uiState.rightPaneSize as number); + uiState.rightPaneSize <= 1 ? uiState.rightPaneSize * window.innerWidth : uiState.rightPaneSize; if (!rightPaneVisible) { return this.renderHorizontalSplit(); diff --git a/public/app/core/history/RichHistoryLocalStorage.test.ts b/public/app/core/history/RichHistoryLocalStorage.test.ts index a7b18c317da..1bbc7f7b30f 100644 --- a/public/app/core/history/RichHistoryLocalStorage.test.ts +++ b/public/app/core/history/RichHistoryLocalStorage.test.ts @@ -151,12 +151,10 @@ describe('RichHistoryLocalStorage', () => { // one not starred replaced with a newly added starred item const removedNotStarredItems = extraItems + 1; // + 1 to make space for the new item - const newHistory = store.getObject(key); + const newHistory = store.getObject(key)!; expect(newHistory).toHaveLength(MAX_HISTORY_ITEMS); // starred item added - expect(newHistory.filter((h: RichHistoryQuery) => h.starred)).toHaveLength(starredItemsInHistory + 1); // starred item added - expect(newHistory.filter((h: RichHistoryQuery) => !h.starred)).toHaveLength( - starredItemsInHistory - removedNotStarredItems - ); + expect(newHistory.filter((h) => h.starred)).toHaveLength(starredItemsInHistory + 1); // starred item added + expect(newHistory.filter((h) => !h.starred)).toHaveLength(starredItemsInHistory - removedNotStarredItems); }); }); diff --git a/public/app/core/store.ts b/public/app/core/store.ts index d66444a0d6b..bcbb338dc23 100644 --- a/public/app/core/store.ts +++ b/public/app/core/store.ts @@ -16,7 +16,9 @@ export class Store { return window.localStorage[key] === 'true'; } - getObject(key: string, def?: any) { + getObject(key: string): T | undefined; + getObject(key: string, def: T): T; + getObject(key: string, def?: T) { let ret = def; if (this.exists(key)) { const json = window.localStorage[key]; diff --git a/public/app/features/canvas/runtime/root.tsx b/public/app/features/canvas/runtime/root.tsx index 25b45a8bba5..1106adddd93 100644 --- a/public/app/features/canvas/runtime/root.tsx +++ b/public/app/features/canvas/runtime/root.tsx @@ -27,12 +27,12 @@ export class RootElement extends GroupState { this.changeCallback(); } - getSaveModel() { + getSaveModel(): CanvasGroupOptions { const { placement, anchor, ...rest } = this.options; return { ...rest, // everything except placement & anchor elements: this.elements.map((v) => v.getSaveModel()), - } as CanvasGroupOptions; + }; } } diff --git a/public/app/features/explore/state/utils.ts b/public/app/features/explore/state/utils.ts index 9bb6b1d968e..49825d2a8d8 100644 --- a/public/app/features/explore/state/utils.ts +++ b/public/app/features/explore/state/utils.ts @@ -96,7 +96,7 @@ export async function loadAndInitDatasource( } const historyKey = `grafana.explore.history.${instance.meta?.id}`; - const history = store.getObject(historyKey, []); + const history = store.getObject(historyKey, []); // Save last-used datasource store.set(lastUsedDatasourceKeyForOrgId(orgId), instance.uid);