From 52d7358d836d32ab43eb75e71019f5ef53a9ec07 Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Fri, 17 Sep 2021 09:47:23 +0100 Subject: [PATCH] Chore: More TypeScript strict fixes (#39300) * Chore: More TypeScript strict fixes * Chore: Use filter instead of reduce to fix TypeScript error * Chore: Retype AzureResultFormat as string * Chore: Account for getBlocks() poor typings of reduce * Chore: Need to explicitly check for undefined here since '' is falsey --- public/app/features/admin/ldap/LdapPage.tsx | 2 +- .../app/plugins/datasource/cloud-monitoring/datasource.ts | 2 +- .../components/InsightsAnalyticsEditor/index.tsx | 4 ++-- .../components/LogsQueryEditor/FormatAsField.tsx | 6 +++--- .../grafana-azure-monitor-datasource/types/types.ts | 2 -- .../app/plugins/datasource/prometheus/language_provider.ts | 5 ++++- scripts/ci-check-strict.sh | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/public/app/features/admin/ldap/LdapPage.tsx b/public/app/features/admin/ldap/LdapPage.tsx index 3f9d05e3d73..900d4fa82db 100644 --- a/public/app/features/admin/ldap/LdapPage.tsx +++ b/public/app/features/admin/ldap/LdapPage.tsx @@ -28,7 +28,7 @@ import { import { GrafanaRouteComponentProps } from 'app/core/navigation/types'; import { contextSrv } from 'app/core/core'; -interface OwnProps extends GrafanaRouteComponentProps<{}, { username: string }> { +interface OwnProps extends GrafanaRouteComponentProps<{}, { username?: string }> { navModel: NavModel; ldapConnectionInfo: LdapConnectionInfo; ldapUser?: LdapUser; diff --git a/public/app/plugins/datasource/cloud-monitoring/datasource.ts b/public/app/plugins/datasource/cloud-monitoring/datasource.ts index 17699efbab6..880565f3389 100644 --- a/public/app/plugins/datasource/cloud-monitoring/datasource.ts +++ b/public/app/plugins/datasource/cloud-monitoring/datasource.ts @@ -357,7 +357,7 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend< value, ...(condition && { condition }), })) - .reduce((res, filter) => (filter.value ? [...res, filter] : res), []); + .filter((item) => item.value); const filterArray = flatten( completeFilter.map(({ key, operator, value, condition }: Filter) => [ diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/InsightsAnalyticsEditor/index.tsx b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/InsightsAnalyticsEditor/index.tsx index 79234c3eef0..0bd61c9531d 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/InsightsAnalyticsEditor/index.tsx +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/InsightsAnalyticsEditor/index.tsx @@ -1,6 +1,6 @@ import { Alert, CodeEditor, Select } from '@grafana/ui'; import React from 'react'; -import { AzureMonitorOption, AzureMonitorQuery, AzureResultFormat } from '../../types'; +import { AzureMonitorOption, AzureMonitorQuery } from '../../types'; import { Field } from '../Field'; import { Space } from '../Space'; @@ -8,7 +8,7 @@ interface InsightsAnalyticsEditorProps { query: AzureMonitorQuery; } -const FORMAT_OPTIONS: Array> = [ +const FORMAT_OPTIONS: Array> = [ { label: 'Time series', value: 'time_series' }, { label: 'Table', value: 'table' }, ]; diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/LogsQueryEditor/FormatAsField.tsx b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/LogsQueryEditor/FormatAsField.tsx index 108e77db6e5..727bc5420e2 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/LogsQueryEditor/FormatAsField.tsx +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/LogsQueryEditor/FormatAsField.tsx @@ -1,11 +1,11 @@ import React, { useCallback, useMemo } from 'react'; import { SelectableValue } from '@grafana/data'; import { Select } from '@grafana/ui'; -import { AzureMonitorOption, AzureQueryEditorFieldProps, AzureResultFormat } from '../../types'; +import { AzureQueryEditorFieldProps } from '../../types'; import { Field } from '../Field'; import { setFormatAs } from './setQueryValue'; -const FORMAT_OPTIONS: Array> = [ +const FORMAT_OPTIONS: Array> = [ { label: 'Time series', value: 'time_series' }, { label: 'Table', value: 'table' }, ]; @@ -14,7 +14,7 @@ const FormatAsField: React.FC = ({ query, variableOp const options = useMemo(() => [...FORMAT_OPTIONS, variableOptionGroup], [variableOptionGroup]); const handleChange = useCallback( - (change: SelectableValue) => { + (change: SelectableValue) => { const { value } = change; if (!value) { return; diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/types/types.ts b/public/app/plugins/datasource/grafana-azure-monitor-datasource/types/types.ts index c4ab753d067..6688551df30 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/types/types.ts +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/types/types.ts @@ -12,8 +12,6 @@ export interface DatasourceValidationResult { title?: string; } -export type AzureResultFormat = 'time_series' | 'table'; - /** * Azure clouds known to Azure Monitor. */ diff --git a/public/app/plugins/datasource/prometheus/language_provider.ts b/public/app/plugins/datasource/prometheus/language_provider.ts index 2116d81ca4b..87e510c2e13 100644 --- a/public/app/plugins/datasource/prometheus/language_provider.ts +++ b/public/app/plugins/datasource/prometheus/language_provider.ts @@ -267,7 +267,10 @@ export default class PromQlLanguageProvider extends LanguageProvider { // Stitch all query lines together to support multi-line queries let queryOffset; - const queryText = value.document.getBlocks().reduce((text: string, block) => { + const queryText = value.document.getBlocks().reduce((text, block) => { + if (text === undefined) { + return ''; + } if (!block) { return text; } diff --git a/scripts/ci-check-strict.sh b/scripts/ci-check-strict.sh index f14b692b94a..84695c81e07 100755 --- a/scripts/ci-check-strict.sh +++ b/scripts/ci-check-strict.sh @@ -3,7 +3,7 @@ set -e echo -e "Collecting code stats (typescript errors & more)" -ERROR_COUNT_LIMIT=46 +ERROR_COUNT_LIMIT=41 ERROR_COUNT="$(./node_modules/.bin/tsc --project tsconfig.json --noEmit --strict true | grep -oP 'Found \K(\d+)')" if [ "$ERROR_COUNT" -gt $ERROR_COUNT_LIMIT ]; then