From 11bf5a03eeae760344a0f8a45d6eee936dcca67e Mon Sep 17 00:00:00 2001 From: Jose Quintas Date: Thu, 11 Apr 2024 15:19:30 +0200 Subject: [PATCH] Make defaultizeValueFormatter types more permissive --- packages/x-charts/src/BarChart/formatter.ts | 5 +---- packages/x-charts/src/LineChart/formatter.ts | 5 +---- packages/x-charts/src/ScatterChart/formatter.ts | 3 +-- packages/x-charts/src/internals/defaultizeValueFormatter.ts | 6 +++--- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/packages/x-charts/src/BarChart/formatter.ts b/packages/x-charts/src/BarChart/formatter.ts index df5df94df1c30..548f363c30106 100644 --- a/packages/x-charts/src/BarChart/formatter.ts +++ b/packages/x-charts/src/BarChart/formatter.ts @@ -87,10 +87,7 @@ const formatter: Formatter<'bar'> = (params, dataset) => { return { seriesOrder, stackingGroups, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - series: defaultizeValueFormatter(completedSeries, (v, _) => - v == null ? '' : v.toLocaleString(), - ), + series: defaultizeValueFormatter(completedSeries, (v) => (v == null ? '' : v.toLocaleString())), }; }; diff --git a/packages/x-charts/src/LineChart/formatter.ts b/packages/x-charts/src/LineChart/formatter.ts index 6393fcbf89fc0..8a7cb0f645894 100644 --- a/packages/x-charts/src/LineChart/formatter.ts +++ b/packages/x-charts/src/LineChart/formatter.ts @@ -84,10 +84,7 @@ const formatter: Formatter<'line'> = (params, dataset) => { return { seriesOrder, stackingGroups, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - series: defaultizeValueFormatter(completedSeries, (v, _) => - v == null ? '' : v.toLocaleString(), - ), + series: defaultizeValueFormatter(completedSeries, (v) => (v == null ? '' : v.toLocaleString())), }; }; diff --git a/packages/x-charts/src/ScatterChart/formatter.ts b/packages/x-charts/src/ScatterChart/formatter.ts index bc6d381eb9bfc..d0db1a6ad0a5a 100644 --- a/packages/x-charts/src/ScatterChart/formatter.ts +++ b/packages/x-charts/src/ScatterChart/formatter.ts @@ -3,8 +3,7 @@ import { Formatter } from '../models/seriesType/config'; const formatter: Formatter<'scatter'> = ({ series, seriesOrder }) => { return { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - series: defaultizeValueFormatter(series, (v, _) => `(${v.x}, ${v.y})`), + series: defaultizeValueFormatter(series, (v) => `(${v.x}, ${v.y})`), seriesOrder, }; }; diff --git a/packages/x-charts/src/internals/defaultizeValueFormatter.ts b/packages/x-charts/src/internals/defaultizeValueFormatter.ts index 06589692068af..f071699c00fb5 100644 --- a/packages/x-charts/src/internals/defaultizeValueFormatter.ts +++ b/packages/x-charts/src/internals/defaultizeValueFormatter.ts @@ -1,8 +1,8 @@ import { SeriesId } from '../models/seriesType/common'; function defaultizeValueFormatter< - ISeries extends { valueFormatter?: IFormatter }, - IFormatter extends (v: any, context: any) => string, + IFormatter extends (v: any, context?: unknown) => string, + ISeries extends { valueFormatter?: Function }, >( series: Record, defaultValueFormatter: IFormatter, @@ -11,7 +11,7 @@ function defaultizeValueFormatter< Object.keys(series).forEach((seriesId) => { defaultizedSeries[seriesId] = { ...series[seriesId], - valueFormatter: series[seriesId].valueFormatter ?? defaultValueFormatter, + valueFormatter: (series[seriesId].valueFormatter as IFormatter) ?? defaultValueFormatter, }; }); return defaultizedSeries;