From 76307c0d024e754ead9cea4b957e57823b955f09 Mon Sep 17 00:00:00 2001 From: Jake Wang Date: Sat, 26 Sep 2026 18:38:59 -0400 Subject: [PATCH] fix(types): allow scriptable and indexed grid tick widths Signed-off-by: Jake Wang --- src/types/index.d.ts | 2 +- test/types/scales/grid.ts | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/types/scales/grid.ts diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 32831adc88c..9427f601d53 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -3101,7 +3101,7 @@ export interface GridLineOptions { /** * @default 1 */ - tickWidth: number; + tickWidth: ScriptableAndArray; /** * @default false */ diff --git a/test/types/scales/grid.ts b/test/types/scales/grid.ts new file mode 100644 index 00000000000..e2f5e1e1949 --- /dev/null +++ b/test/types/scales/grid.ts @@ -0,0 +1,25 @@ +import { Chart, GridLineOptions, ScriptableScaleContext } from '../../../src/types.js'; + +const grid: Partial = { + tickWidth: (context: ScriptableScaleContext) => context.tick.value === 0 ? 2 : 1 +}; + +const chart = new Chart('test', { + type: 'line', + data: { datasets: [] }, + options: { + scales: { + x: { grid }, + y: { + grid: { + tickWidth: (context) => { + const scaleContext: ScriptableScaleContext = context; + return scaleContext.tick.value === 0 ? 2 : 1; + } + } + }, + y1: { grid: { tickWidth: [1, 2] } }, + y2: { grid: { tickWidth: 2 } } + } + } +});