From 21e53fcc523f2e79b3de24d6ff74827b1c4f9a42 Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Sat, 26 Jul 2025 22:27:15 -0400 Subject: [PATCH 1/2] Fix types for scriptable `init` It takes its parameters as a context object, not three separate parameters. configuration.md and migrationV3.md explain that it returns an AnnotationBoxModel, not an AnnotationElement. --- types/options.d.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/types/options.d.ts b/types/options.d.ts index 86e31ca7e..081bd4dac 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -138,11 +138,17 @@ export interface LabelAnnotationOptions extends CoreAnnotationOptions, LabelType rotation?: Scriptable } +interface InitContext { + chart: Chart, + properties: AnnotationBoxModel, + options: AnnotationOptions +} + export interface DoughnutLabelAnnotationOptions extends AnnotationEvents, DoughnutLabelOptions, ShadowOptions { autoFit?: Scriptable, autoHide?: Scriptable, id?: string, - init: boolean | ((chart: Chart, properties: AnnotationBoxModel, options: AnnotationOptions) => void | boolean | AnnotationBoxModel), + init: boolean | ((ctx: InitContext) => void | boolean | AnnotationElement), spacing?: Scriptable } From 4cf1a3d0a96ce354a0aaaaf93c10b31f21f464c9 Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Tue, 29 Jul 2025 17:35:20 -0400 Subject: [PATCH 2/2] Fix and further consolidate init types --- types/options.d.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/types/options.d.ts b/types/options.d.ts index 081bd4dac..bce5e1a15 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -35,6 +35,14 @@ interface ShadowOptions { shadowOffsetY?: Scriptable } +export interface InitContext { + chart: Chart, + properties: AnnotationBoxModel, + options: AnnotationOptions +} + +export type ScriptableInit = boolean | ((ctx: InitContext) => void | boolean | Partial); + export interface CoreAnnotationOptions extends AnnotationEvents, ShadowOptions, AnnotationHooks { adjustScaleRange?: Scriptable, borderColor?: Scriptable, @@ -44,7 +52,7 @@ export interface CoreAnnotationOptions extends AnnotationEvents, ShadowOptions, display?: Scriptable, drawTime?: Scriptable, hitTolerance?: Scriptable, - init?: boolean | (({ chart: Chart, properties: AnnotationBoxModel, options: AnnotationOptions }) => void | boolean | Partial), + init?: ScriptableInit, id?: string, xMax?: Scriptable, xMin?: Scriptable, @@ -138,17 +146,11 @@ export interface LabelAnnotationOptions extends CoreAnnotationOptions, LabelType rotation?: Scriptable } -interface InitContext { - chart: Chart, - properties: AnnotationBoxModel, - options: AnnotationOptions -} - export interface DoughnutLabelAnnotationOptions extends AnnotationEvents, DoughnutLabelOptions, ShadowOptions { autoFit?: Scriptable, autoHide?: Scriptable, id?: string, - init: boolean | ((ctx: InitContext) => void | boolean | AnnotationElement), + init?: ScriptableInit, spacing?: Scriptable }