Chore: Remove several 'as' type assertions (#45913)

This commit is contained in:
kay delaney
2022-03-02 14:02:09 +00:00
committed by GitHub
parent 47d1d83673
commit f530775e45
10 changed files with 23 additions and 26 deletions

View File

@@ -5,7 +5,7 @@ import { Icon, IconName } from '@grafana/ui';
export interface FooterLink { export interface FooterLink {
text: string; text: string;
id?: string; id?: string;
icon?: string; icon?: IconName;
url?: string; url?: string;
target?: string; target?: string;
} }
@@ -77,7 +77,7 @@ export const Footer: FC = React.memo(() => {
{links.map((link) => ( {links.map((link) => (
<li key={link.text}> <li key={link.text}>
<a href={link.url} target={link.target} rel="noopener" id={link.id}> <a href={link.url} target={link.target} rel="noopener" id={link.id}>
{link.icon && <Icon name={link.icon as IconName} />} {link.text} {link.icon && <Icon name={link.icon} />} {link.text}
</a> </a>
</li> </li>
))} ))}

View File

@@ -12,10 +12,10 @@ export interface Props {
export default class PageActionBar extends PureComponent<Props> { export default class PageActionBar extends PureComponent<Props> {
render() { render() {
const { searchQuery, linkButton, setSearchQuery, target, placeholder = 'Search by name or type' } = this.props; 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) { if (target) {
(linkProps as any).target = target; linkProps.target = target;
} }
return ( return (

View File

@@ -41,8 +41,8 @@ class AddPermissions extends Component<Props, NewDashboardAclItem> {
}; };
} }
onTypeChanged = (item: any) => { onTypeChanged = (item: SelectableValue<AclTarget>) => {
const type = item.value as AclTarget; const type = item.value;
switch (type) { switch (type) {
case AclTarget.User: case AclTarget.User:

View File

@@ -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 { css, cx } from '@emotion/css';
import { useStyles2, getInputStyles, sharedInputStyle, styleMixins, Tooltip, Icon } from '@grafana/ui'; import { useStyles2, getInputStyles, sharedInputStyle, styleMixins, Tooltip, Icon } from '@grafana/ui';
import { GrafanaTheme2 } from '@grafana/data'; import { GrafanaTheme2 } from '@grafana/data';
@@ -36,7 +36,7 @@ export const RolePickerInput = ({
useEffect(() => { useEffect(() => {
if (isFocused) { if (isFocused) {
(inputRef as MutableRefObject<HTMLInputElement>).current?.focus(); inputRef.current?.focus();
} }
}); });

View File

@@ -1,6 +1,6 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import { useAsync } from 'react-use'; import { useAsync } from 'react-use';
import { Icon, IconName, Select } from '@grafana/ui'; import { Icon, Select } from '@grafana/ui';
import { SelectableValue } from '@grafana/data'; import { SelectableValue } from '@grafana/data';
import { DEFAULT_SORT } from 'app/features/search/constants'; import { DEFAULT_SORT } from 'app/features/search/constants';
import { SearchSrv } from '../../services/search_srv'; import { SearchSrv } from '../../services/search_srv';
@@ -36,7 +36,7 @@ export const SortPicker: FC<Props> = ({ onChange, value, placeholder, filter })
options={options} options={options}
aria-label="Sort" aria-label="Sort"
placeholder={placeholder ?? `Sort (Default ${DEFAULT_SORT.label})`} placeholder={placeholder ?? `Sort (Default ${DEFAULT_SORT.label})`}
prefix={<Icon name={(value?.includes('asc') ? 'sort-amount-up' : 'sort-amount-down') as IconName} />} prefix={<Icon name={value?.includes('asc') ? 'sort-amount-up' : 'sort-amount-down'} />}
/> />
) : null; ) : null;
}; };

View File

@@ -19,7 +19,7 @@ interface Props {
} }
export class SplitPaneWrapper extends PureComponent<Props> { export class SplitPaneWrapper extends PureComponent<Props> {
rafToken = createRef<number>(); rafToken: MutableRefObject<number | null> = createRef();
static defaultProps = { static defaultProps = {
rightPaneVisible: true, rightPaneVisible: true,
}; };
@@ -36,7 +36,7 @@ export class SplitPaneWrapper extends PureComponent<Props> {
if (this.rafToken.current !== undefined) { if (this.rafToken.current !== undefined) {
window.cancelAnimationFrame(this.rafToken.current!); window.cancelAnimationFrame(this.rafToken.current!);
} }
(this.rafToken as MutableRefObject<number>).current = window.requestAnimationFrame(() => { this.rafToken.current = window.requestAnimationFrame(() => {
this.forceUpdate(); this.forceUpdate();
}); });
}; };
@@ -68,8 +68,7 @@ export class SplitPaneWrapper extends PureComponent<Props> {
renderHorizontalSplit() { renderHorizontalSplit() {
const { leftPaneComponents, uiState } = this.props; const { leftPaneComponents, uiState } = this.props;
const styles = getStyles(config.theme); const styles = getStyles(config.theme);
const topPaneSize = const topPaneSize = uiState.topPaneSize >= 1 ? uiState.topPaneSize : uiState.topPaneSize * window.innerHeight;
uiState.topPaneSize >= 1 ? (uiState.topPaneSize as number) : (uiState.topPaneSize as number) * window.innerHeight;
/* /*
Guesstimate the height of the browser window minus Guesstimate the height of the browser window minus
@@ -104,9 +103,7 @@ export class SplitPaneWrapper extends PureComponent<Props> {
// Need to handle when width is relative. ie a percentage of the viewport // Need to handle when width is relative. ie a percentage of the viewport
const rightPaneSize = const rightPaneSize =
uiState.rightPaneSize <= 1 uiState.rightPaneSize <= 1 ? uiState.rightPaneSize * window.innerWidth : uiState.rightPaneSize;
? (uiState.rightPaneSize as number) * window.innerWidth
: (uiState.rightPaneSize as number);
if (!rightPaneVisible) { if (!rightPaneVisible) {
return this.renderHorizontalSplit(); return this.renderHorizontalSplit();

View File

@@ -151,12 +151,10 @@ describe('RichHistoryLocalStorage', () => {
// one not starred replaced with a newly added starred item // one not starred replaced with a newly added starred item
const removedNotStarredItems = extraItems + 1; // + 1 to make space for the new item const removedNotStarredItems = extraItems + 1; // + 1 to make space for the new item
const newHistory = store.getObject(key); const newHistory = store.getObject<typeof history>(key)!;
expect(newHistory).toHaveLength(MAX_HISTORY_ITEMS); // starred item added 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) => h.starred)).toHaveLength(starredItemsInHistory + 1); // starred item added
expect(newHistory.filter((h: RichHistoryQuery) => !h.starred)).toHaveLength( expect(newHistory.filter((h) => !h.starred)).toHaveLength(starredItemsInHistory - removedNotStarredItems);
starredItemsInHistory - removedNotStarredItems
);
}); });
}); });

View File

@@ -16,7 +16,9 @@ export class Store {
return window.localStorage[key] === 'true'; return window.localStorage[key] === 'true';
} }
getObject(key: string, def?: any) { getObject<T = unknown>(key: string): T | undefined;
getObject<T = unknown>(key: string, def: T): T;
getObject<T = unknown>(key: string, def?: T) {
let ret = def; let ret = def;
if (this.exists(key)) { if (this.exists(key)) {
const json = window.localStorage[key]; const json = window.localStorage[key];

View File

@@ -27,12 +27,12 @@ export class RootElement extends GroupState {
this.changeCallback(); this.changeCallback();
} }
getSaveModel() { getSaveModel(): CanvasGroupOptions {
const { placement, anchor, ...rest } = this.options; const { placement, anchor, ...rest } = this.options;
return { return {
...rest, // everything except placement & anchor ...rest, // everything except placement & anchor
elements: this.elements.map((v) => v.getSaveModel()), elements: this.elements.map((v) => v.getSaveModel()),
} as CanvasGroupOptions; };
} }
} }

View File

@@ -96,7 +96,7 @@ export async function loadAndInitDatasource(
} }
const historyKey = `grafana.explore.history.${instance.meta?.id}`; const historyKey = `grafana.explore.history.${instance.meta?.id}`;
const history = store.getObject(historyKey, []); const history = store.getObject<HistoryItem[]>(historyKey, []);
// Save last-used datasource // Save last-used datasource
store.set(lastUsedDatasourceKeyForOrgId(orgId), instance.uid); store.set(lastUsedDatasourceKeyForOrgId(orgId), instance.uid);