You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/02/12 03:18:41 UTC

(superset) branch fix/type-errors-master created (now 6838b1a4645)

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a change to branch fix/type-errors-master
in repository https://gitbox.apache.org/repos/asf/superset.git


      at 6838b1a4645 fix(types): add explicit types for extendedDayjs plugin methods

This branch includes the following new commits:

     new 6838b1a4645 fix(types): add explicit types for extendedDayjs plugin methods

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(superset) 01/01: fix(types): add explicit types for extendedDayjs plugin methods

Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch fix/type-errors-master
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 6838b1a46452f450bfcb4b2b41f048442d12dcda
Author: Evan Rusackas <ev...@rusackas.com>
AuthorDate: Wed Feb 11 19:18:23 2026 -0800

    fix(types): add explicit types for extendedDayjs plugin methods
    
    The extendedDayjs export was typed as `typeof dayjs` which didn't
    include the plugin methods (utc, tz, duration, etc.) added at runtime.
    This caused TS2339 errors in consuming code when calling methods like
    `extendedDayjs.utc()`.
    
    Added explicit `ExtendedDayjs` and `ExtendedDayjsFactory` interfaces
    that include all the plugin methods, making the types match the runtime
    behavior.
    
    Co-Authored-By: Claude Opus 4.5 <no...@anthropic.com>
---
 .../packages/superset-ui-core/src/utils/dates.ts   | 52 ++++++++++++++++++++--
 1 file changed, 48 insertions(+), 4 deletions(-)

diff --git a/superset-frontend/packages/superset-ui-core/src/utils/dates.ts b/superset-frontend/packages/superset-ui-core/src/utils/dates.ts
index 9594f15c988..eb099035843 100644
--- a/superset-frontend/packages/superset-ui-core/src/utils/dates.ts
+++ b/superset-frontend/packages/superset-ui-core/src/utils/dates.ts
@@ -17,13 +17,13 @@
  * under the License.
  */
 
-import dayjs, { Dayjs } from 'dayjs';
+import dayjs, { Dayjs, ConfigType } from 'dayjs';
 import utc from 'dayjs/plugin/utc';
 import timezone from 'dayjs/plugin/timezone';
 import calendar from 'dayjs/plugin/calendar';
 import relativeTime from 'dayjs/plugin/relativeTime';
 import customParseFormat from 'dayjs/plugin/customParseFormat';
-import duration from 'dayjs/plugin/duration';
+import duration, { Duration, DurationUnitType } from 'dayjs/plugin/duration';
 import updateLocale from 'dayjs/plugin/updateLocale';
 import localizedFormat from 'dayjs/plugin/localizedFormat';
 
@@ -40,8 +40,52 @@ dayjs.updateLocale('en', {
   invalidDate: 'Invalid date',
 });
 
-export const extendedDayjs = dayjs;
-export type { Dayjs };
+/**
+ * Extended dayjs instance with all plugins loaded.
+ * Explicitly typed to include plugin methods that are added at runtime.
+ */
+export interface ExtendedDayjs extends Dayjs {
+  utc(keepLocalTime?: boolean): Dayjs;
+  local(): Dayjs;
+  isUTC(): boolean;
+  tz(timezone?: string, keepLocalTime?: boolean): Dayjs;
+  fromNow(withoutSuffix?: boolean): string;
+  toNow(withoutSuffix?: boolean): string;
+  from(compared: ConfigType, withoutSuffix?: boolean): string;
+  to(compared: ConfigType, withoutSuffix?: boolean): string;
+  calendar(referenceTime?: ConfigType, formats?: object): string;
+}
+
+/**
+ * Extended dayjs static interface with all plugins loaded.
+ */
+export interface ExtendedDayjsFactory {
+  (config?: ConfigType, format?: string, strict?: boolean): ExtendedDayjs;
+  utc(config?: ConfigType, format?: string, strict?: boolean): ExtendedDayjs;
+  tz: {
+    (input?: ConfigType, timezone?: string): ExtendedDayjs;
+    (input?: ConfigType, format?: string, timezone?: string): ExtendedDayjs;
+    guess(): string;
+    setDefault(timezone?: string): void;
+  };
+  duration(input?: number | string | object, unit?: DurationUnitType): Duration;
+  isDuration(d: unknown): d is Duration;
+  unix(timestamp: number): ExtendedDayjs;
+  locale(preset?: string | object, object?: object, isLocal?: boolean): string;
+  updateLocale(locale: string, customConfig: object): object;
+  extend<T = unknown>(
+    plugin: (
+      option: T,
+      dayjsClass: typeof Dayjs,
+      dayjsFactory: typeof dayjs,
+    ) => void,
+    option?: T,
+  ): typeof dayjs;
+  isDayjs(d: unknown): d is Dayjs;
+}
+
+export const extendedDayjs = dayjs as unknown as ExtendedDayjsFactory;
+export type { Dayjs, Duration, ConfigType };
 
 export const fDuration = function (
   t1: number,