any/type assertion fixes (#57009)

This commit is contained in:
Ashley Harrison
2022-10-17 10:10:10 +01:00
committed by GitHub
parent e25475b9c8
commit 3cca8e3676
27 changed files with 67 additions and 309 deletions

View File

@@ -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"]
],

View File

@@ -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,
};
};

View File

@@ -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<DataLinkInputProps> = memo(
({ value, onChange, suggestions, placeholder = 'http://your-grafana.com/d/000000010/annotations' }) => {
const editorRef = useRef<Editor>() as RefObject<Editor>;
const editorRef = useRef<Editor>(null);
const styles = useStyles2(getStyles);
const [showingSuggestions, setShowingSuggestions] = useState(false);
const [suggestionsIndex, setSuggestionsIndex] = useState(0);

View File

@@ -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() {

View File

@@ -23,8 +23,8 @@ export const FormattedValueDisplay: FC<Props> = ({ 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 };
}

View File

@@ -89,9 +89,10 @@ const mockGraphProps = (multiSeries = false) => {
};
};
(window as any).ResizeObserver = class ResizeObserver {
window.ResizeObserver = class ResizeObserver {
constructor() {}
observe() {}
unobserve() {}
disconnect() {}
};

View File

@@ -117,8 +117,9 @@ export class Graph extends PureComponent<GraphProps, GraphState> {
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,

View File

@@ -15,7 +15,7 @@ export function getIntervalFromString(strInterval: string): SelectableValue<numb
}
interface Props {
func: () => any; // TODO
func: () => unknown;
loading: boolean;
interval: string;
}

View File

@@ -19,7 +19,7 @@ interface Props<V, D> {
renderValue: (props: VizRepeaterRenderValueProps<V, D>) => 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;

View File

@@ -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(<PageHeader navItem={nav as any} />);
render(<PageHeader navItem={nav} />);
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(<PageHeader navItem={nav as any} />);
render(<PageHeader navItem={nav} />);
expect(screen.getByRole('heading', { name: 'Parent / child' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Parent' })).toBeInTheDocument();

View File

@@ -7,7 +7,7 @@ export interface Props {
item: DashboardAcl;
}
export default class DisabledPermissionListItem extends Component<Props, any> {
export default class DisabledPermissionListItem extends Component<Props> {
render() {
const { item } = this.props;
const currentPermissionLevel = dashboardPermissionLevels.find((dp) => dp.value === item.permission);

View File

@@ -413,7 +413,7 @@ export const RolePickerSubMenu = ({
);
};
interface RoleMenuOptionProps<T> {
interface RoleMenuOptionProps {
data: Role;
onChange: (value: Role) => void;
isSelected?: boolean;
@@ -422,7 +422,7 @@ interface RoleMenuOptionProps<T> {
hideDescription?: boolean;
}
export const RoleMenuOption = React.forwardRef<HTMLDivElement, React.PropsWithChildren<RoleMenuOptionProps<any>>>(
export const RoleMenuOption = React.forwardRef<HTMLDivElement, React.PropsWithChildren<RoleMenuOptionProps>>(
({ data, isFocused, isSelected, disabled, onChange, hideDescription }, ref) => {
const theme = useTheme2();
const styles = getSelectStyles(theme);

View File

@@ -9,7 +9,7 @@ export interface Props {
onClick?: React.MouseEventHandler<HTMLDivElement>;
}
export class TagBadge extends React.Component<Props, any> {
export class TagBadge extends React.Component<Props> {
constructor(props: Props) {
super(props);
}

View File

@@ -4,12 +4,12 @@ import { TagBadge } from './TagBadge';
export interface Props {
value: any;
className: any;
className: string;
onClick: React.MouseEventHandler<HTMLDivElement>;
onRemove: any;
onRemove: (value: any, event: React.MouseEvent<HTMLDivElement>) => void;
}
export class TagValue extends React.Component<Props, any> {
export class TagValue extends React.Component<Props> {
constructor(props: Props) {
super(props);
this.onClick = this.onClick.bind(this);

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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;
}
}

View File

@@ -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));
}
}

View File

@@ -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);

View File

@@ -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() {

View File

@@ -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<Settings>,
[]
);
const { loading, value: settings } = useAsync(() => getBackendSrv().get<Settings>('/api/admin/settings'), []);
return (
<Page navId="server-settings">

View File

@@ -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<ComponentType<FilterProps>> = [];

View File

@@ -130,10 +130,10 @@ export class AlertRuleListUnconnected extends PureComponent<Props> {
{alertRules.map((rule) => {
return (
<AlertRuleItem
rule={rule as AlertRule}
rule={rule}
key={rule.id}
search={search}
onTogglePause={() => this.onTogglePause(rule as AlertRule)}
onTogglePause={() => this.onTogglePause(rule)}
/>
);
})}

View File

@@ -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,

View File

@@ -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
}

View File

@@ -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(() => {