From c9b0d8d5aff5a4c0590cf5c6236eff6644bdbff9 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Fri, 19 Dec 2025 00:19:16 -0800 Subject: [PATCH] fix(types): fix TypeScript errors in SqlLab actions and AnnotationLayer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SqlLab actions: - Use `as const` for action creators to preserve literal types - Allows proper type inference for ReturnType - Fixes errors in src/core/sqlLab/index.ts which uses ReturnType AnnotationLayer: - Handle possibly undefined props in constructor - Create processedOverrides to avoid mutating undefined - Add default values for all optional state properties 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../src/SqlLab/actions/sqlLab.ts | 22 ++++------ .../AnnotationLayer.tsx | 41 ++++++++++--------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.ts b/superset-frontend/src/SqlLab/actions/sqlLab.ts index 152ffd94ca9..848ef9175a0 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.ts +++ b/superset-frontend/src/SqlLab/actions/sqlLab.ts @@ -306,10 +306,7 @@ export function clearInactiveQueries(interval: number): SqlLabAction { return { type: CLEAR_INACTIVE_QUERIES, interval }; } -export function startQuery( - query: Query, - runPreviewOnly?: boolean, -): SqlLabAction { +export function startQuery(query: Query, runPreviewOnly?: boolean) { Object.assign(query, { id: query.id ? query.id : nanoid(11), progress: 0, @@ -317,14 +314,11 @@ export function startQuery( state: query.runAsync ? 'pending' : 'running', cached: false, }); - return { type: START_QUERY, query, runPreviewOnly }; + return { type: START_QUERY, query, runPreviewOnly } as const; } -export function querySuccess( - query: Query, - results: QueryResponse, -): SqlLabAction { - return { type: QUERY_SUCCESS, query, results }; +export function querySuccess(query: Query, results: QueryResponse) { + return { type: QUERY_SUCCESS, query, results } as const; } export function logFailedQuery( @@ -358,8 +352,8 @@ export function createQueryFailedAction( msg: string, link?: string, errors?: SupersetError[], -): SqlLabAction { - return { type: QUERY_FAILED, query, msg, link, errors }; +) { + return { type: QUERY_FAILED, query, msg, link, errors } as const; } export function queryFailed( @@ -374,8 +368,8 @@ export function queryFailed( }; } -export function stopQuery(query: Query): SqlLabAction { - return { type: STOP_QUERY, query }; +export function stopQuery(query: Query) { + return { type: STOP_QUERY, query } as const; } export function clearQueryResults(query: Query): SqlLabAction { diff --git a/superset-frontend/src/explore/components/controls/AnnotationLayerControl/AnnotationLayer.tsx b/superset-frontend/src/explore/components/controls/AnnotationLayerControl/AnnotationLayer.tsx index 8e9c2502df1..850437cb3b6 100644 --- a/superset-frontend/src/explore/components/controls/AnnotationLayerControl/AnnotationLayer.tsx +++ b/superset-frontend/src/explore/components/controls/AnnotationLayerControl/AnnotationLayer.tsx @@ -204,10 +204,11 @@ class AnnotationLayer extends PureComponent< } = props; // Only allow override whole time_range - if ('since' in overrides || 'until' in overrides) { - overrides.time_range = null; - delete overrides.since; - delete overrides.until; + const processedOverrides: AnnotationOverrides = overrides ? { ...overrides } : {}; + if ('since' in processedOverrides || 'until' in processedOverrides) { + processedOverrides.time_range = null; + delete processedOverrides.since; + delete processedOverrides.until; } // Check if annotationType is supported by this chart @@ -221,25 +222,25 @@ class AnnotationLayer extends PureComponent< this.state = { // base - name, - annotationType: validAnnotationType, - sourceType, - value, - overrides, - show, - showLabel, + name: name || '', + annotationType: validAnnotationType || DEFAULT_ANNOTATION_TYPE, + sourceType: sourceType || null, + value: value || null, + overrides: processedOverrides, + show: show ?? true, + showLabel: showLabel ?? false, // slice - titleColumn, - descriptionColumns, - timeColumn, - intervalEndColumn, + titleColumn: titleColumn || '', + descriptionColumns: descriptionColumns || [], + timeColumn: timeColumn || '', + intervalEndColumn: intervalEndColumn || '', // display color: color || AUTOMATIC_COLOR, - opacity, - style, - width, - showMarkers, - hideLine, + opacity: opacity || '', + style: style || 'solid', + width: width ?? 1, + showMarkers: showMarkers ?? false, + hideLine: hideLine ?? false, // refData isNew: !name, slice: null,