[scanner] fix: replace 'any' types with proper type annotations#19862
Conversation
Replaces 25 uses of the 'any' type with proper type annotations to improve type safety: Test files (using specific interfaces and unknown): - EnterpriseSidebar.test.tsx: Mock component props with interfaces - EnterpriseLayout.test.tsx: Mock customizer props with interface - ClusterGrid.common.test.tsx: React.KeyboardEvent types for event handlers - CreateDashboardModal.test.tsx: Specific modal props interfaces - ui-data-components.test.tsx: Removed unnecessary 'any' casts - WorkloadsExtended.test.tsx: Proper mock data interfaces Production code: - VClusterActionBanner.tsx: Removed 'any' cast for i18n translation keys All changes maintain existing functionality while improving type safety. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: clubanderson <clubanderson@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
|
🐝 Hi @clubanderson! I'm Trusted users — org members and contributors with write access — can mention Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies. |
✅ Test Coverage CheckAll new source files in this PR have corresponding test files. Checked |
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #19856 by improving TypeScript type-safety, primarily in tests, by replacing any usages with explicit interfaces/types and safer casts, and by removing unnecessary any casts in production i18n calls.
Changes:
- Replaced
anyin multiple test mocks/fixtures with explicit interfaces and more specific event/argument typings. - Removed
anycasts around i18n translation key usage inVClusterActionBanner. - Tightened mock signatures (e.g.,
unknown[], generic identity functions) to reduce implicitanyusage.
Build/lint are expected to be validated by CI on the PR.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| web/src/components/workloads/tests/WorkloadsExtended.test.tsx | Replaces any arrays and mock signatures with interfaces/generics/unknown[]; adjusts useGlobalFilters mocks. |
| web/src/components/settings/sections/VClusterActionBanner.tsx | Removes any casts on i18n translation key calls. |
| web/src/components/mission-control/tests/ui-data-components.test.tsx | Removes any casts in component props, aiming for type-correct test inputs. |
| web/src/components/enterprise/tests/EnterpriseSidebar.test.tsx | Adds typed mock props for SidebarShell and removes any in iteration. |
| web/src/components/enterprise/tests/EnterpriseLayout.test.tsx | Adds typed mock props for DashboardCustomizer. |
| web/src/components/dashboard/tests/CreateDashboardModal.test.tsx | Adds typed mock props for modal header/footer and removes any casts. |
| web/src/components/clusters/components/tests/ClusterGrid.common.test.tsx | Replaces any casts with React.KeyboardEvent-typed casts for handlers. |
| assignment={{ | ||
| clusterName: 'eks-prod', | ||
| projectNames: ['falco'], | ||
| readiness: { overallScore: 85, cpuHeadroomPercent: 75, memHeadroomPercent: 75, storageHeadroomPercent: 100 }, | ||
| warnings: [] | ||
| } as unknown as any} | ||
| }} |
| availableProjects={['falco']} | ||
| assignment={{ | ||
| clusterName: 'eks-prod', | ||
| projectNames: [], | ||
| readiness: { overallScore: 85 }, | ||
| warnings: [] | ||
| } as unknown as any} | ||
| }} |
| onAddProject={vi.fn()} | ||
| onRemoveProject={vi.fn()} | ||
| onUpdatePriority={vi.fn()} | ||
| aiStreaming={true} | ||
| planningMission={{ status: 'running', messages: [] } as unknown as any} | ||
| planningMission={{ status: 'running', messages: [] }} | ||
| /> |
| vi.mocked(useGlobalFilters).mockReturnValue({ | ||
| selectedClusters: [], | ||
| isAllClustersSelected: true, | ||
| customFilter: 'nginx', | ||
| filterByCluster: (items: any[]) => items, | ||
| } as any) | ||
| filterByCluster: <T,>(items: T[]) => items, | ||
| }) |
| vi.mocked(useGlobalFilters).mockReturnValue({ | ||
| selectedClusters: [], | ||
| isAllClustersSelected: true, | ||
| customFilter: '', | ||
| filterByCluster: (items: any[]) => items, | ||
| } as any) | ||
| filterByCluster: <T,>(items: T[]) => items, | ||
| }) |
| vi.mocked(useGlobalFilters).mockReturnValue({ | ||
| selectedClusters: [], | ||
| isAllClustersSelected: true, | ||
| customFilter: '', | ||
| filterByCluster: (items: any[]) => items, | ||
| } as any) | ||
| filterByCluster: <T,>(items: T[]) => items, | ||
| }) |
…anner Dynamic translation keys built at runtime cannot match the static union of known keys, so `as any` is the necessary escape hatch. The other 24 `any` removals in test files remain — this only restores the 2 production-code assertions that broke the build. Signed-off-by: clubanderson <andy@kubestellar.io>
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
✅ Post-Merge Verification: passedCommit: |
Fixes #19856
Replaces 25 uses of the
anytype with proper type annotations to improve type safety.Changes
Test files (using specific interfaces and proper types):
EnterpriseSidebar.test.tsx: Mock component props with interfacesEnterpriseLayout.test.tsx: Mock customizer props with interfaceClusterGrid.common.test.tsx:React.KeyboardEventtypes for event handlersCreateDashboardModal.test.tsx: Specific modal props interfacesui-data-components.test.tsx: Removed unnecessary any castsWorkloadsExtended.test.tsx: Proper mock data interfacesProduction code:
VClusterActionBanner.tsx: Removed any cast for i18n translation keys