Chore: improve some more types (#60476)

* improve some more types

* fixes

Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This commit is contained in:
Ashley Harrison 2022-12-20 13:07:57 +00:00 committed by GitHub
parent 55b014974d
commit ba6d2f2a82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 43 additions and 66 deletions

View File

@ -35,12 +35,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"] [0, 0, 0, "Unexpected any. Specify a different type.", "1"]
], ],
"e2e/dashboards-suite/textbox-variables.spec.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"]
],
"e2e/panels-suite/panelEdit_queries.spec.ts:5381": [ "e2e/panels-suite/panelEdit_queries.spec.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"], [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.", "1"]
@ -974,19 +968,13 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "2"] [0, 0, 0, "Unexpected any. Specify a different type.", "2"]
], ],
"packages/grafana-runtime/src/utils/DataSourceWithBackend.ts:5381": [ "packages/grafana-runtime/src/utils/DataSourceWithBackend.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Do not use any type assertions.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"], [0, 0, 0, "Do not use any type assertions.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"], [0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Do not use any type assertions.", "4"], [0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Do not use any type assertions.", "5"], [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.", "6"]
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Do not use any type assertions.", "9"],
[0, 0, 0, "Do not use any type assertions.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
[0, 0, 0, "Do not use any type assertions.", "12"]
], ],
"packages/grafana-runtime/src/utils/plugin.ts:5381": [ "packages/grafana-runtime/src/utils/plugin.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"] [0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@ -994,21 +982,14 @@ exports[`better eslint`] = {
"packages/grafana-runtime/src/utils/queryResponse.test.ts:5381": [ "packages/grafana-runtime/src/utils/queryResponse.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"], [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.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"], [0, 0, 0, "Unexpected any. Specify a different type.", "2"]
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
], ],
"packages/grafana-runtime/src/utils/queryResponse.ts:5381": [ "packages/grafana-runtime/src/utils/queryResponse.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "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.", "1"],
[0, 0, 0, "Do not use any type assertions.", "2"], [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.", "3"],
[0, 0, 0, "Do not use any type assertions.", "4"], [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"]
],
"packages/grafana-runtime/src/utils/toDataQueryError.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"]
], ],
"packages/grafana-toolkit/src/cli/tasks/component.create.ts:5381": [ "packages/grafana-toolkit/src/cli/tasks/component.create.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -1108,9 +1089,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "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.", "1"]
], ],
"packages/grafana-ui/src/components/ButtonCascader/ButtonCascader.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"packages/grafana-ui/src/components/Card/Card.tsx:5381": [ "packages/grafana-ui/src/components/Card/Card.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"] [0, 0, 0, "Unexpected any. Specify a different type.", "1"]
@ -1127,10 +1105,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "2"], [0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Do not use any type assertions.", "3"] [0, 0, 0, "Do not use any type assertions.", "3"]
], ],
"packages/grafana-ui/src/components/CustomScrollbar/CustomScrollbar.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"packages/grafana-ui/src/components/DataLinks/DataLinkInput.tsx:5381": [ "packages/grafana-ui/src/components/DataLinks/DataLinkInput.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"], [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.", "1"],

View File

@ -33,8 +33,8 @@ describe.skip('TextBox - change query scenarios', function () {
saveDashboard(false); saveDashboard(false);
e2e() e2e()
.get('@dashuid') .get<string>('@dashuid')
.then((dashuid: any) => { .then((dashuid) => {
expect(dashuid).not.to.eq(PAGE_UNDER_TEST); expect(dashuid).not.to.eq(PAGE_UNDER_TEST);
e2e.flows.openDashboard({ uid: dashuid }); e2e.flows.openDashboard({ uid: dashuid });
@ -59,8 +59,8 @@ describe.skip('TextBox - change query scenarios', function () {
saveDashboard(true); saveDashboard(true);
e2e() e2e()
.get('@dashuid') .get<string>('@dashuid')
.then((dashuid: any) => { .then((dashuid) => {
expect(dashuid).not.to.eq(PAGE_UNDER_TEST); expect(dashuid).not.to.eq(PAGE_UNDER_TEST);
e2e.flows.openDashboard({ uid: dashuid }); e2e.flows.openDashboard({ uid: dashuid });
@ -85,8 +85,8 @@ describe.skip('TextBox - change picker value scenarios', function () {
saveDashboard(false); saveDashboard(false);
e2e() e2e()
.get('@dashuid') .get<string>('@dashuid')
.then((dashuid: any) => { .then((dashuid) => {
expect(dashuid).not.to.eq(PAGE_UNDER_TEST); expect(dashuid).not.to.eq(PAGE_UNDER_TEST);
e2e.flows.openDashboard({ uid: dashuid }); e2e.flows.openDashboard({ uid: dashuid });
@ -108,8 +108,8 @@ describe.skip('TextBox - change picker value scenarios', function () {
saveDashboard(true); saveDashboard(true);
e2e() e2e()
.get('@dashuid') .get<string>('@dashuid')
.then((dashuid: any) => { .then((dashuid) => {
expect(dashuid).not.to.eq(PAGE_UNDER_TEST); expect(dashuid).not.to.eq(PAGE_UNDER_TEST);
e2e.flows.openDashboard({ uid: dashuid }); e2e.flows.openDashboard({ uid: dashuid });

View File

@ -23,6 +23,7 @@ export {
frameToMetricFindValue, frameToMetricFindValue,
type BackendDataSourceResponse, type BackendDataSourceResponse,
type DataResponse, type DataResponse,
type TestingStatus,
} from './utils/queryResponse'; } from './utils/queryResponse';
export { PanelRenderer, type PanelRendererProps } from './components/PanelRenderer'; export { PanelRenderer, type PanelRendererProps } from './components/PanelRenderer';
export { PanelDataErrorView, type PanelDataErrorViewProps } from './components/PanelDataErrorView'; export { PanelDataErrorView, type PanelDataErrorViewProps } from './components/PanelDataErrorView';

View File

@ -46,7 +46,7 @@ export function isExpressionReference(ref?: DataSourceRef | string | null): bool
if (!ref) { if (!ref) {
return false; return false;
} }
const v = (ref as any).type ?? ref; const v = typeof ref === 'string' ? ref : ref.type;
return v === ExpressionDatasourceRef.type || v === '-100'; // -100 was a legacy accident that should be removed return v === ExpressionDatasourceRef.type || v === '-100'; // -100 was a legacy accident that should be removed
} }
@ -88,7 +88,7 @@ enum PluginRequestHeaders {
* *
* @public * @public
*/ */
export type HealthCheckResultDetails = Record<string, any> | undefined; export type HealthCheckResultDetails = Record<string, unknown> | undefined;
/** /**
* Describes the payload returned when checking the health of a data source * Describes the payload returned when checking the health of a data source
@ -320,8 +320,8 @@ class DataSourceWithBackend<
headers: this.getRequestHeaders(), headers: this.getRequestHeaders(),
}) })
) )
.then((v: FetchResponse) => v.data as HealthCheckResult) .then((v: FetchResponse) => v.data)
.catch((err) => err.data as HealthCheckResult); .catch((err) => err.data);
} }
/** /**
@ -360,7 +360,7 @@ export function toStreamingDataResponse<TQuery extends DataQuery = DataQuery>(
for (const f of rsp.data) { for (const f of rsp.data) {
const addr = parseLiveChannelAddress(f.meta?.channel); const addr = parseLiveChannelAddress(f.meta?.channel);
if (addr) { if (addr) {
const frame = f as DataFrame; const frame: DataFrame = f;
streams.push( streams.push(
live.getDataStream({ live.getDataStream({
addr, addr,

View File

@ -280,7 +280,7 @@ describe('Query Response parser', () => {
}); });
describe('Cache notice', () => { describe('Cache notice', () => {
let resp: any; let resp: FetchResponse<BackendDataSourceResponse>;
beforeEach(() => { beforeEach(() => {
resp = { resp = {
@ -311,7 +311,7 @@ describe('Query Response parser', () => {
test('does not remove existing notices', () => { test('does not remove existing notices', () => {
const queries: DataQuery[] = [{ refId: 'A' }]; const queries: DataQuery[] = [{ refId: 'A' }];
resp.headers.set('X-Cache', 'HIT'); resp.headers.set('X-Cache', 'HIT');
resp.data.results.A.frames[0].schema.meta = { notices: [{ severity: 'info', text: 'Example' }] }; resp.data.results.A.frames![0].schema!.meta = { notices: [{ severity: 'info', text: 'Example' }] };
expect(toDataQueryResponse(resp, queries).data[0].meta.notices).toStrictEqual([ expect(toDataQueryResponse(resp, queries).data[0].meta.notices).toStrictEqual([
{ severity: 'info', text: 'Example' }, { severity: 'info', text: 'Example' },
cachedResponseNotice, cachedResponseNotice,

View File

@ -17,6 +17,7 @@ import {
import { FetchError, FetchResponse } from '../services'; import { FetchError, FetchResponse } from '../services';
import { HealthCheckResultDetails } from './DataSourceWithBackend';
import { toDataQueryError } from './toDataQueryError'; import { toDataQueryError } from './toDataQueryError';
export const cachedResponseNotice: QueryResultMetaNotice = { severity: 'info', text: 'Cached response' }; export const cachedResponseNotice: QueryResultMetaNotice = { severity: 'info', text: 'Cached response' };
@ -130,7 +131,7 @@ export function toDataQueryResponse(
rsp.state = LoadingState.Error; rsp.state = LoadingState.Error;
} }
if (!rsp.error) { if (!rsp.error) {
rsp.error = toDataQueryError(res as DataQueryError); rsp.error = toDataQueryError(res);
} }
} }
@ -160,6 +161,12 @@ function addCacheNotice(frame: DataFrameJSON): DataFrameJSON {
}; };
} }
export interface TestingStatus {
message?: string | null;
status?: string | null;
details?: HealthCheckResultDetails;
}
/** /**
* Data sources using api/ds/query to test data sources can use this function to * Data sources using api/ds/query to test data sources can use this function to
* handle errors and convert them to TestingStatus object. * handle errors and convert them to TestingStatus object.
@ -171,7 +178,7 @@ function addCacheNotice(frame: DataFrameJSON): DataFrameJSON {
* *
* @returns {TestingStatus} * @returns {TestingStatus}
*/ */
export function toTestingStatus(err: FetchError): any { export function toTestingStatus(err: FetchError): TestingStatus {
const queryResponse = toDataQueryResponse(err); const queryResponse = toDataQueryResponse(err);
// POST api/ds/query errors returned as { message: string, error: string } objects // POST api/ds/query errors returned as { message: string, error: string } objects
if (queryResponse.error?.data?.message) { if (queryResponse.error?.data?.message) {

View File

@ -7,11 +7,11 @@ import { DataQueryError } from '@grafana/data';
* @public * @public
*/ */
export function toDataQueryError(err: DataQueryError | string | unknown): DataQueryError { export function toDataQueryError(err: DataQueryError | string | unknown): DataQueryError {
const error = (err || {}) as DataQueryError; const error: DataQueryError = err || {};
if (!error.message) { if (!error.message) {
if (typeof err === 'string' || err instanceof String) { if (typeof err === 'string') {
return { message: err } as DataQueryError; return { message: err };
} }
let message = 'Query error'; let message = 'Query error';

View File

@ -51,7 +51,7 @@ export const ButtonCascader: React.FC<ButtonCascaderProps> = (props) => {
// Weird way to do this bit it goes around a styling issue in Button where even null/undefined child triggers // Weird way to do this bit it goes around a styling issue in Button where even null/undefined child triggers
// styling change which messes up the look if there is only single icon content. // styling change which messes up the look if there is only single icon content.
let content: any = props.children; let content: React.ReactNode = props.children;
if (!hideDownIcon) { if (!hideDownIcon) {
content = [props.children, <Icon key={'down-icon'} name="angle-down" className={styles.icons.right} />]; content = [props.children, <Icon key={'down-icon'} name="angle-down" className={styles.icons.right} />];
} }

View File

@ -49,7 +49,7 @@ export const CustomScrollbar = ({
onScroll, onScroll,
children, children,
}: React.PropsWithChildren<Props>) => { }: React.PropsWithChildren<Props>) => {
const ref = useRef<Scrollbars & { view: HTMLDivElement }>(null); const ref = useRef<Scrollbars & { view: HTMLDivElement; update: () => void }>(null);
const styles = useStyles2(getStyles); const styles = useStyles2(getStyles);
useEffect(() => { useEffect(() => {
@ -73,7 +73,7 @@ export const CustomScrollbar = ({
return; return;
} }
setTimeout(() => { setTimeout(() => {
const scrollbar = ref.current as any; const scrollbar = ref.current;
if (scrollbar?.update) { if (scrollbar?.update) {
scrollbar.update(); scrollbar.update();
} }

View File

@ -1,8 +1,8 @@
import React from 'react'; import React from 'react';
import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; import { selectors as e2eSelectors } from '@grafana/e2e-selectors';
import { TestingStatus } from '@grafana/runtime';
import { Alert } from '@grafana/ui'; import { Alert } from '@grafana/ui';
import { TestingStatus } from 'app/types';
export type Props = { export type Props = {
testingStatus?: TestingStatus; testingStatus?: TestingStatus;

View File

@ -1,7 +1,8 @@
import { AnyAction, createAction } from '@reduxjs/toolkit'; import { AnyAction, createAction } from '@reduxjs/toolkit';
import { DataSourcePluginMeta, DataSourceSettings, LayoutMode, LayoutModes } from '@grafana/data'; import { DataSourcePluginMeta, DataSourceSettings, LayoutMode, LayoutModes } from '@grafana/data';
import { DataSourcesState, DataSourceSettingsState, TestingStatus } from 'app/types'; import { TestingStatus } from '@grafana/runtime';
import { DataSourcesState, DataSourceSettingsState } from 'app/types';
import { GenericDataSourcePlugin } from '../types'; import { GenericDataSourcePlugin } from '../types';

View File

@ -1,5 +1,5 @@
import { DataSourcePluginMeta, DataSourceSettings, LayoutMode } from '@grafana/data'; import { DataSourcePluginMeta, DataSourceSettings, LayoutMode } from '@grafana/data';
import { HealthCheckResultDetails } from '@grafana/runtime/src/utils/DataSourceWithBackend'; import { TestingStatus } from '@grafana/runtime';
import { GenericDataSourcePlugin } from 'app/features/datasources/types'; import { GenericDataSourcePlugin } from 'app/features/datasources/types';
export interface DataSourcesState { export interface DataSourcesState {
@ -17,12 +17,6 @@ export interface DataSourcesState {
isSortAscending: boolean; isSortAscending: boolean;
} }
export interface TestingStatus {
message?: string | null;
status?: string | null;
details?: HealthCheckResultDetails;
}
export interface DataSourceSettingsState { export interface DataSourceSettingsState {
plugin?: GenericDataSourcePlugin | null; plugin?: GenericDataSourcePlugin | null;
testingStatus?: TestingStatus; testingStatus?: TestingStatus;