From fb7d036fa43a266da093e18cfe06afcf4f975978 Mon Sep 17 00:00:00 2001 From: Marcus Andersson Date: Tue, 16 Jun 2020 07:34:27 +0200 Subject: [PATCH] Typescript: Fixed strict null errors. (#25609) --- public/app/plugins/panel/bargauge/BarGaugePanel.tsx | 2 +- public/app/plugins/panel/gauge/GaugePanel.tsx | 2 +- public/app/plugins/panel/graph/module.ts | 5 ++--- public/app/plugins/panel/news/module.tsx | 3 ++- public/app/plugins/panel/singlestat/specs/singlestat.test.ts | 2 +- public/app/plugins/panel/stat/StatPanel.tsx | 2 +- scripts/ci-frontend-metrics.sh | 4 +--- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/public/app/plugins/panel/bargauge/BarGaugePanel.tsx b/public/app/plugins/panel/bargauge/BarGaugePanel.tsx index ab80e09ca8e..710e968f8c5 100644 --- a/public/app/plugins/panel/bargauge/BarGaugePanel.tsx +++ b/public/app/plugins/panel/bargauge/BarGaugePanel.tsx @@ -45,7 +45,7 @@ export class BarGaugePanel extends PureComponent> { const { value } = valueProps; const { hasLinks, getLinks } = value; - if (!hasLinks) { + if (!hasLinks || !getLinks) { return this.renderComponent(valueProps, {}); } diff --git a/public/app/plugins/panel/gauge/GaugePanel.tsx b/public/app/plugins/panel/gauge/GaugePanel.tsx index 8aa6f46c76e..e80ece45340 100644 --- a/public/app/plugins/panel/gauge/GaugePanel.tsx +++ b/public/app/plugins/panel/gauge/GaugePanel.tsx @@ -35,7 +35,7 @@ export class GaugePanel extends PureComponent> { const { value } = valueProps; const { getLinks, hasLinks } = value; - if (!hasLinks) { + if (!hasLinks || !getLinks) { return this.renderComponent(valueProps, {}); } diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts index 12419cd9c80..fe2f8a8d22d 100644 --- a/public/app/plugins/panel/graph/module.ts +++ b/public/app/plugins/panel/graph/module.ts @@ -246,7 +246,7 @@ class GraphCtrl extends MetricsPanelCtrl { ); } - getDataWarning(): DataWarning { + getDataWarning(): DataWarning | undefined { const datapointsCount = this.seriesList.reduce((prev, series) => { return prev + series.datapoints.length; }, 0); @@ -302,8 +302,7 @@ class GraphCtrl extends MetricsPanelCtrl { return dataWarning; } - - return null; + return undefined; } onRender() { diff --git a/public/app/plugins/panel/news/module.tsx b/public/app/plugins/panel/news/module.tsx index ff42a3c4792..d9cfa9071b7 100755 --- a/public/app/plugins/panel/news/module.tsx +++ b/public/app/plugins/panel/news/module.tsx @@ -1,3 +1,4 @@ +import { isString } from 'lodash'; import { PanelPlugin } from '@grafana/data'; import { NewsPanel } from './NewsPanel'; import { NewsOptions } from './types'; @@ -18,7 +19,7 @@ export const plugin = new PanelPlugin(NewsPanel).setPanelOptions(bu name: 'Use Proxy', description: 'If the feed is unable to connect, consider a CORS proxy', showIf: (currentConfig: NewsOptions) => { - return currentConfig.feedUrl && !currentConfig.feedUrl.startsWith(PROXY_PREFIX); + return isString(currentConfig.feedUrl) && !currentConfig.feedUrl.startsWith(PROXY_PREFIX); }, }); }); diff --git a/public/app/plugins/panel/singlestat/specs/singlestat.test.ts b/public/app/plugins/panel/singlestat/specs/singlestat.test.ts index 5c922439ae0..ade7fbed9f3 100644 --- a/public/app/plugins/panel/singlestat/specs/singlestat.test.ts +++ b/public/app/plugins/panel/singlestat/specs/singlestat.test.ts @@ -90,7 +90,7 @@ describe('SingleStatCtrl', () => { }); it('Should use series avg as default main value', () => { - const name = getFieldDisplayName(ctx.data.field); + const name = getFieldDisplayName(ctx.data.field!); expect(name).toBe('test.cpu1'); }); diff --git a/public/app/plugins/panel/stat/StatPanel.tsx b/public/app/plugins/panel/stat/StatPanel.tsx index eae1cb33401..f9435f36bd5 100644 --- a/public/app/plugins/panel/stat/StatPanel.tsx +++ b/public/app/plugins/panel/stat/StatPanel.tsx @@ -65,7 +65,7 @@ export class StatPanel extends PureComponent> { const { value } = valueProps; const { getLinks, hasLinks } = value; - if (!hasLinks) { + if (!hasLinks || !getLinks) { return this.renderComponent(valueProps, {}); } diff --git a/scripts/ci-frontend-metrics.sh b/scripts/ci-frontend-metrics.sh index da20c528517..18ad5153190 100755 --- a/scripts/ci-frontend-metrics.sh +++ b/scripts/ci-frontend-metrics.sh @@ -2,9 +2,7 @@ echo -e "Collecting code stats (typescript errors & more)" - - -ERROR_COUNT_LIMIT=726 +ERROR_COUNT_LIMIT=724 DIRECTIVES_LIMIT=172 CONTROLLERS_LIMIT=139