diff --git a/src/core/core.adapters.ts b/src/core/core.adapters.ts index 6c9b2b032..282d13699 100644 --- a/src/core/core.adapters.ts +++ b/src/core/core.adapters.ts @@ -19,19 +19,19 @@ export interface DateAdapter { * Returns a map of time formats for the supported formatting units defined * in Unit as well as 'datetime' representing a detailed date/time string. */ - formats(this: DateAdapter): Record; + formats(this: DateAdapter): Record; /** * Parses the given `value` and return the associated timestamp. * @param value - the value to parse (usually comes from the data) * @param [format] - the expected data format */ - parse(this: DateAdapter, value: unknown, format?: TimeUnit): number | null; + parse(this: DateAdapter, value: unknown, format?: string): number | null; /** * Returns the formatted date in the specified `format` for a given `timestamp`. * @param timestamp - the timestamp to format * @param format - the date/time token */ - format(this: DateAdapter, timestamp: number, format: TimeUnit): string; + format(this: DateAdapter, timestamp: number, format: string): string; /** * Adds the specified `amount` of `unit` to the given `timestamp`. * @param timestamp - the input timestamp @@ -53,13 +53,13 @@ export interface DateAdapter { * @param [weekday] - the ISO day of the week with 1 being Monday * and 7 being Sunday (only needed if param *unit* is `isoWeek`). */ - startOf(this: DateAdapter, timestamp: number, unit: TimeUnit | 'isoWeek', weekday?: number): number; + startOf(this: DateAdapter, timestamp: number, unit: TimeUnit | 'isoWeek', weekday?: number | boolean): number; /** * Returns end of `unit` for the given `timestamp`. * @param timestamp - the input timestamp * @param unit - the unit as string */ - endOf(this: DateAdapter, timestamp: number, unit: TimeUnit | 'isoWeek'): number; + endOf(this: DateAdapter, timestamp: number, unit: TimeUnit): number; } function abstract(): T { @@ -92,14 +92,14 @@ class DateAdapterBase implements DateAdapter { readonly options: AnyObject; - constructor(options: AnyObject) { + constructor(options?: AnyObject) { this.options = options || {}; } // eslint-disable-next-line @typescript-eslint/no-empty-function init() {} - formats(): Record { + formats(): Record { return abstract(); } @@ -129,5 +129,10 @@ class DateAdapterBase implements DateAdapter { } export default { - _date: DateAdapterBase + _date: DateAdapterBase as { + new (options?: AnyObject): DateAdapter; + override( + members: Partial, 'options'>> + ): void; + } }; diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 184937466..f82d43ad7 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -59,7 +59,7 @@ function parse(scale, input) { // Only parse if it's not a timestamp already if (!isFinite(value)) { value = typeof parser === 'string' - ? adapter.parse(value, /** @type {Unit} */ (parser)) + ? adapter.parse(value, parser) : adapter.parse(value); }