diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 32831adc88c..8a6915fd393 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -3430,7 +3430,7 @@ export type TimeScaleTimeOptions = { /** * Custom parser for dates. */ - parser: string | ((v: unknown) => number); + parser?: string | ((v: unknown) => number); /** * If defined, dates will be rounded to the start of this unit. See Time Units below for the allowed units. */ @@ -3450,7 +3450,7 @@ export type TimeScaleTimeOptions = { /** * The format string to use for the tooltip. */ - tooltipFormat: string; + tooltipFormat?: string; /** * If defined, will force the unit to be a certain type. See Time Units section below for details. * @default false diff --git a/test/types/scales/time_options.ts b/test/types/scales/time_options.ts new file mode 100644 index 00000000000..a088af76dd0 --- /dev/null +++ b/test/types/scales/time_options.ts @@ -0,0 +1,24 @@ +import type { TimeScaleTimeOptions } from '../../../src/types.js'; + +// `time.parser` and `time.tooltipFormat` have no default value, so they must stay +// optional when the resolved time scale options are referenced directly. +const minimal: TimeScaleTimeOptions = { + unit: 'year', + round: false, + isoWeekday: false, + minUnit: 'millisecond', + displayFormats: { + month: 'yy' + } +}; + +const withParser: TimeScaleTimeOptions = { + ...minimal, + parser: 'yyyy-MM-dd', + tooltipFormat: 'eeee, MMM dd, yyyy' +}; + +const withParserFunction: TimeScaleTimeOptions = { + ...minimal, + parser: (value: unknown) => Number(value) +};