Feature Proposal
TimeScaleTimeOptions is declared as a type alias, which prevents adapters from widening displayFormats or tooltipFormat via TypeScript module augmentation.
At runtime, Chart.js passes displayFormats values straight through to adapter.format() without any string-specific operations:
// chart.js/dist/chart.js line 11232
return this._adapter.format(value, fmt);
This means adapters can accept richer format types (e.g. Intl.DateTimeFormatOptions objects, callbacks) and everything works at runtime. But TypeScript rejects it because displayFormats is typed as { [key: string]: string } inside a type alias that can't be augmented.
Context
Possible Implementation
Change TimeScaleTimeOptions from a type to an interface:
- export type TimeScaleTimeOptions = {
+ export interface TimeScaleTimeOptions {
parser: string | ((v: unknown) => number);
round: false | TimeUnit;
isoWeekday: boolean | number;
displayFormats: {
[key: string]: string;
};
tooltipFormat: string;
unit: false | TimeUnit;
minUnit: TimeUnit;
}
This should be a non-breaking change — interface and type are interchangeable for object shapes. But it would allow adapters to augment displayFormats and tooltipFormat via declaration merging:
// In an adapter package
declare module 'chart.js' {
interface TimeScaleTimeOptions {
displayFormats: {
[key: string]: string | Intl.DateTimeFormatOptions | ((timestamp: number, context: FormatContext) => string);
};
}
}
Feature Proposal
TimeScaleTimeOptionsis declared as atypealias, which prevents adapters from wideningdisplayFormatsortooltipFormatvia TypeScript module augmentation.At runtime, Chart.js passes
displayFormatsvalues straight through toadapter.format()without any string-specific operations:This means adapters can accept richer format types (e.g. Intl.DateTimeFormatOptions objects, callbacks) and everything works at runtime. But TypeScript rejects it because displayFormats is typed as { [key: string]: string } inside a type alias that can't be augmented.
Context
Temporal/Intltime adapter, as a path to no external date library requirement #12140 (proposal for an official Temporal/Intl adapter)Possible Implementation
Change TimeScaleTimeOptions from a type to an interface:
This should be a non-breaking change — interface and type are interchangeable for object shapes. But it would allow adapters to augment displayFormats and tooltipFormat via declaration merging: