codeant-ai-for-open-source[bot] commented on code in PR #37923:
URL: https://github.com/apache/superset/pull/37923#discussion_r2796584790
##########
superset-frontend/packages/superset-ui-core/src/utils/dates.ts:
##########
@@ -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;
Review Comment:
**Suggestion:** The instance plugin methods on the extended date type
currently return the base `Dayjs` type, so chaining plugin methods (e.g.
calling `utc()` and then another plugin method) downgrades the type and can
reintroduce missing-method type errors instead of preserving the extended,
fully-typed interface. [type error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Prevents fluent chaining of extendedDayjs instance plugin methods.
- ⚠️ Encourages unsafe any-casts in date UI components.
- ⚠️ Affects date handling in filters and dashboard labels.
- ⚠️ Suggestion improves typing; current runtime behavior still correct.
```
</details>
```suggestion
utc(keepLocalTime?: boolean): ExtendedDayjs;
local(): ExtendedDayjs;
isUTC(): boolean;
tz(timezone?: string, keepLocalTime?: boolean): ExtendedDayjs;
```
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Note the extended instance interface in
`superset-frontend/packages/superset-ui-core/src/utils/dates.ts:47-57`, where
`ExtendedDayjs.utc()` and `ExtendedDayjs.tz()` are declared to return the
base `Dayjs`
type, not `ExtendedDayjs`.
2. Observe a real caller that obtains an `ExtendedDayjs` instance, e.g.
`dttmToDayjs()` in
`superset-frontend/src/explore/components/controls/DateFilterControl/utils/dateParser.ts:42-50`,
which returns `extendedDayjs().utc().startOf('second')` for the `"now"` case.
3. In any existing consumer that imports `extendedDayjs`, for example
`LastUpdated` in
`superset-frontend/packages/superset-ui-core/src/components/LastUpdated/index.tsx:24-52`,
add a line like `const tzExample =
extendedDayjs(updatedAt).utc().tz('America/New_York');`
inside the component body.
4. Run TypeScript type checking (the repo already type-checks these files);
the compiler
will report `TS2339: Property 'tz' does not exist on type 'Dayjs'` at the
new call site,
because the call `extendedDayjs(updatedAt)` returns `ExtendedDayjs` but
`.utc()` is typed
to return `Dayjs`, which does not include plugin methods like `tz`, even
though they are
available at runtime.
```
</details>
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/packages/superset-ui-core/src/utils/dates.ts
**Line:** 48:51
**Comment:**
*Type Error: The instance plugin methods on the extended date type
currently return the base `Dayjs` type, so chaining plugin methods (e.g.
calling `utc()` and then another plugin method) downgrades the type and can
reintroduce missing-method type errors instead of preserving the extended,
fully-typed interface.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37923&comment_hash=64aceae4e6fc48b6b121c433b5934ae8962d17ad80794a80eab4d37a48163913&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37923&comment_hash=64aceae4e6fc48b6b121c433b5934ae8962d17ad80794a80eab4d37a48163913&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]