Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/types/scales/time_options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { 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)
};