Skip to content

fix: resolve TS2345 in PerspectivePlugins customElements.define#1844

Merged
mdesmet merged 2 commits intomasterfrom
fix/perspective-plugin-ts-error
Mar 24, 2026
Merged

fix: resolve TS2345 in PerspectivePlugins customElements.define#1844
mdesmet merged 2 commits intomasterfrom
fix/perspective-plugin-ts-error

Conversation

@ralphstodomingo
Copy link
Contributor

@ralphstodomingo ralphstodomingo commented Mar 23, 2026

Summary

  • Adds type cast for PerspectiveDatagridJSONViewerPlugin at the customElements.define() call to fix TS2345 build error
  • Fixes ?? operator precedence bug in 4 files where the nullish fallback was inside .map() (always no-op) instead of outside it

Context

TS2345: Started after PR #1833 (b0a58e4a) changed moduleResolution from "node" to "bundler" in webview_panels/tsconfig.json. Under "bundler" resolution, TypeScript requires customElements.define() arguments to fully satisfy CustomElementConstructor. The plugin class extends its base dynamically via customElements.get(), which TS cannot statically verify — the cast is safe at runtime.

?? precedence: tags?.map((v) => ({ label: v, value: v }) ?? []) — the ?? [] applied to each mapped object literal (always truthy, never triggered). Fixed to tags?.map((v) => ({ label: v, value: v })) ?? [] so the fallback correctly applies when the source array is nullish. Same behavior when the array exists, correct fallback when it doesn't.

Test plan

  • npx tsc --noEmit passes with zero errors
  • Vite build completes without ?? operator warnings

…define` call

Cast `PerspectiveDatagridJSONViewerPlugin` to `CustomElementConstructor` to
satisfy TypeScript's stricter type checking under `moduleResolution: "bundler"`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

Walkthrough

Small, localized edits: added a type cast when registering a custom element, simplified Select value/defaultValue mapping to remove redundant nullish-coalescing, and reordered some imports in two components. No runtime logic or control flow changes.

Changes

Cohort / File(s) Summary
Custom Element Type Casting
webview_panels/src/modules/queryPanel/components/perspective/PerspectivePlugins.ts
Changed customElements.define() to cast PerspectiveDatagridJSONViewerPlugin as unknown as CustomElementConstructor.
Select value/defaultValue simplifications
webview_panels/src/modules/documentationEditor/components/tests/forms/AcceptedValues.tsx, webview_panels/src/modules/queryPanel/components/filters/Filters.tsx, webview_panels/src/modules/queryPanel/components/queryPanelBookmarks/BookmarkButton.tsx
Removed redundant ?? []/inner nullish-coalescing inside map() expressions for value/defaultValue, consolidating empty-array fallback at the top level. No behavioral change.
Import reordering
webview_panels/src/modules/documentationEditor/components/tests/forms/AcceptedValues.tsx, webview_panels/src/modules/queryPanel/components/queryPanelBookmarks/BookmarkButton.tsx
Reordered and regrouped imports (logger, request executors, hooks/actions) — purely organizational, no runtime logic changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: fixing a TypeScript TS2345 error in the PerspectivePlugins customElements.define call.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description is well-structured with clear problem/solution sections, detailed context explaining the TS2345 build error and ?? precedence bug, and a comprehensive test plan with verifiable steps.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/perspective-plugin-ts-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ralphstodomingo ralphstodomingo self-assigned this Mar 23, 2026
The `?? []` fallback was inside the `.map()` callback, applying to each
mapped object literal (always truthy, so always a no-op). Moved it outside
so it applies to the nullable array itself: `arr?.map(...) ?? []`.

Fixes esbuild warnings: "The ?? operator here will always return the left operand"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mdesmet mdesmet merged commit 77f6e9b into master Mar 24, 2026
17 checks passed
@mdesmet mdesmet deleted the fix/perspective-plugin-ts-error branch March 24, 2026 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants