-
-
Notifications
You must be signed in to change notification settings - Fork 358
fix(components): Remove 'any' types from React components (#1034) #1974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(components): Remove 'any' types from React components (#1034) #1974
Conversation
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1974 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 30 30
Lines 633 655 +22
Branches 196 214 +18
=========================================
+ Hits 633 655 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR successfully removes 'any' type annotations from core React components and page files, replacing them with proper TypeScript types. The changes improve type safety across 4 main components (JsonEditor, Layout, GettingStarted, Code) and multiple page files that handle markdown content rendering.
Key changes:
- Created a centralized
types/common.tsfile with shared type definitions (Frontmatter, Author, NavLink, etc.) - Replaced 'any' types in component props with specific types (Frontmatter, string, React.ReactNode)
- Added explicit type annotations to array operations (reduce, map, find) in JsonEditor and GettingStarted
- Improved event handler type safety in Layout component
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| types/common.ts | New centralized type definitions file with interfaces for Frontmatter, Author, NavLink, and other shared types |
| components/JsonEditor.tsx | Comprehensive type safety improvements: added RenderLeafProps/RenderElementProps types, explicit reduce() type annotations, proper type guards for Descendant iteration, and Record<string, RangeWithSyntaxPart[]> for decoration maps |
| components/Layout.tsx | Replaced 'any' with explicit store state type { overlayNavigation: string | null } and proper event.target casting to Node |
| components/GettingStarted.tsx | Added inline type annotations for find() operations and proper SchemaOption/InstanceOption interfaces |
| components/Code.tsx | Replaced 'any' with React.ReactNode for children prop |
| components/DocTable.tsx | Made frontmatter properties optional and added proper type handling with conditional rendering for optional fields |
| pages/understanding-json-schema/reference/[slug].page.tsx | Replaced 'any' types with Frontmatter and string, added Frontmatter import, changed || to ?? for null coalescing |
| pages/understanding-json-schema/index.page.tsx | Simplified component props by removing unused frontmatter and content parameters, typed blocks as string[] |
| pages/understanding-json-schema/[slug].page.tsx | Replaced 'any' types with Frontmatter and string, added Frontmatter import, used nullish coalescing operator |
| pages/specification/release-notes/index.page.tsx | Added BlocksData interface, typed frontmatter as Frontmatter, added conditional rendering for optional blocks.body |
| pages/specification/migration/index.page.tsx | Added BlocksData interface, typed frontmatter as Frontmatter, added conditional rendering for optional blocks.body |
| pages/specification/json-hyper-schema/index.page.tsx | Added SpecificationFrontmatter and BlocksData interfaces, conditional rendering for optional frontmatter fields |
| pages/overview/sponsors/index.page.tsx | Typed blocks prop as string[] instead of any[] |
| pages/overview/code-of-conduct/index.page.tsx | Simplified component props to only include blocks: string[], removed unused parameters |
| pages/overview/[slug].page.tsx | Replaced 'any' with Frontmatter and string, added optional chaining for navigation links |
| pages/learn/getting-started-step-by-step/index.page.tsx | Simplified component props to blocks: string[] |
| pages/learn/[slug].page.tsx | Replaced 'any' types with Frontmatter and string, used nullish coalescing |
| pages/implementers/index.page.tsx | Typed blocks as string[] instead of any[] |
| pages/implementers/[slug].page.tsx | Replaced 'any' types with Frontmatter and string |
| pages/draft/2020-12/index.page.tsx | Added DraftFrontmatter and BlocksData interfaces extending base types |
| pages/draft/2020-12/[slug].page.tsx | Replaced 'any' with Frontmatter and string types |
| pages/draft/2019-09/index.page.tsx | Added DraftFrontmatter and BlocksData interfaces |
| pages/draft/2019-09/[slug].page.tsx | Replaced 'any' with Frontmatter and string types |
| pages/draft-07/index.page.tsx | Added DraftFrontmatter and BlocksData interfaces |
| pages/draft-07/[slug].page.tsx | Replaced 'any' with Frontmatter and string types |
| pages/draft-06/index.page.tsx | Added DraftFrontmatter and BlocksData interfaces |
| pages/draft-06/[slug].page.tsx | Replaced 'any' with Frontmatter and string types |
| pages/draft-05/index.page.tsx | Added DraftFrontmatter and BlocksData interfaces with required body field |
| pages/ambassadors/index.page.tsx | Typed ambassadorData as string instead of any |
| pages/[slug].page.tsx | Replaced 'any' with Frontmatter and string, used type import |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
614fefc to
d141e96
Compare
What kind of change does this PR introduce?
This PR eliminates 'any' type annotations from core React components through proper type guards and specific type definitions.
Issue Number:
anyfrom codebase #1034Summary
Removes implicit 'any' types from 4 React components.
Key changes included:
JsonEditor.tsx: ReplacedRecord<string, any>withRecord<string, RangeWithSyntaxPart[]>andnull | anywithRecord<string, unknown> | nullCode.tsx,GettingStarted.tsx,Layout.tsx: Fixed reduce() type issues with explicit type annotationsType Safety Improvements:
Does this PR introduce a breaking change?
No. Component interfaces remain backward compatible.
Checklist