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
This commit is contained in:
Ashley Harrison 2021-09-17 09:47:23 +01:00 committed by GitHub
parent 5eb46281a4
commit 52d7358d83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 12 additions and 11 deletions

View File

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

View File

@ -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) => [

View File

@ -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<AzureMonitorOption<AzureResultFormat>> = [
const FORMAT_OPTIONS: Array<AzureMonitorOption<string>> = [
{ label: 'Time series', value: 'time_series' },
{ label: 'Table', value: 'table' },
];

View File

@ -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<AzureMonitorOption<AzureResultFormat>> = [
const FORMAT_OPTIONS: Array<SelectableValue<string>> = [
{ label: 'Time series', value: 'time_series' },
{ label: 'Table', value: 'table' },
];
@ -14,7 +14,7 @@ const FormatAsField: React.FC<AzureQueryEditorFieldProps> = ({ query, variableOp
const options = useMemo(() => [...FORMAT_OPTIONS, variableOptionGroup], [variableOptionGroup]);
const handleChange = useCallback(
(change: SelectableValue<AzureResultFormat>) => {
(change: SelectableValue<string>) => {
const { value } = change;
if (!value) {
return;

View File

@ -12,8 +12,6 @@ export interface DatasourceValidationResult {
title?: string;
}
export type AzureResultFormat = 'time_series' | 'table';
/**
* Azure clouds known to Azure Monitor.
*/

View File

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

View File

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