fix(libs): Remove 'any' types from utilities, libraries, and tests (#1034)#1975
fix(libs): Remove 'any' types from utilities, libraries, and tests (#1034)#1975vtushar06 wants to merge 3 commits intojson-schema-org:mainfrom
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 #1975 +/- ##
=========================================
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.
Pull request overview
This PR successfully completes the removal of 'any' type annotations from utility functions, library code, and test files across the JSON Schema website codebase. The changes improve type safety, include defensive coding practices, and fix several potential runtime issues.
Key changes:
- Created centralized type definitions in
types/common.tsfor reusable interfaces - Replaced all
anytypes with proper TypeScript types across 40+ files - Added conditional rendering guards to prevent undefined values from causing errors
- Improved date handling to avoid invalid Date object creation
Reviewed changes
Copilot reviewed 44 out of 44 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| types/common.ts | New file with centralized type definitions (Frontmatter, BlogPost, CalendarEventInfo, etc.) |
| lib/calendarUtils.ts | Added proper types from node-ical, created CalendarEventInfo interface, improved type safety |
| lib/getStaticMarkdownProps.ts | Added proper return type and Frontmatter interface |
| lib/getScopesOfParsedJsonSchema.ts | Added ParsedJsonSchema interface, improved reduce type annotations |
| lib/getPartsOfJson.ts | Added proper types for reduce operations and array elements |
| lib/slugifyMarkdownHeadline.ts | Improved type annotation for reduce operation |
| pages/blog/index.page.tsx | Added type guards for category filtering, proper Frontmatter interface |
| pages/blog/posts/[slug].page.tsx | Fixed date handling to avoid invalid Date objects |
| pages/blog/generateRssFeed.tsx | Added BlogPost and BlogPostFrontmatter interfaces, improved optional property handling |
| pages/index.page.tsx | Modernized file filtering with endsWith(), added proper blog post and event types |
| pages/community/index.page.tsx | Added proper types for blog posts and calendar events |
| pages/_app.page.tsx | Removed use of any for Component, added proper type for getLayout |
| pages/[slug].page.tsx | Added Frontmatter type from common types |
| pages/specification/* | Added proper types, conditional rendering for optional frontmatter fields |
| pages/draft/* | Added DraftFrontmatter and BlocksData interfaces |
| pages/overview/* | Added Frontmatter type, improved optional chaining |
| pages/learn/* | Added Frontmatter type |
| pages/implementers/* | Added Frontmatter type |
| pages/ambassadors/index.page.tsx | Changed ambassadorData type from any to string |
| components/Layout.tsx | Added proper store type, improved event.target casting |
| components/JsonEditor.tsx | Added proper Slate types (RenderLeafProps, RenderElementProps), improved type safety throughout |
| components/GettingStarted.tsx | Added proper types for options and instances |
| components/DocTable.tsx | Added Author interface, conditional rendering for optional fields |
| components/Code.tsx | Changed children type from any to React.ReactNode |
| cypress/plugins/mockNextRouterUtils.ts | Added proper Cypress and Sinon stub types |
| cypress/components/*.cy.tsx | Added proper types for mock functions and parameters |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const files = fs.readdirSync(PATH); | ||
| const blogPosts = files | ||
| const blogPosts: BlogPost[] = files | ||
| .filter((file) => file.substr(-3) === '.md') |
There was a problem hiding this comment.
[nitpick] For consistency with the change made in pages/index.page.tsx line 31, consider using .endsWith('.md') instead of .substr(-3) === '.md'. The endsWith() method is more modern and clearer in intent.
| .filter((file) => file.substr(-3) === '.md') | |
| .filter((file) => file.endsWith('.md')) |
5c5d77a to
60e21c3
Compare
|
Hii @Utkarsh-123github, can you please review this PR when possible by you. |
What kind of change does this PR introduce?
This PR completes the removal of 'any' type annotations from utility functions, library code, and test files.
Issue Number:
anyfrom codebase #1034Summary
Finalizes the complete elimination of 'any' type annotations across the remaining library utilities, utility functions, blog pages, and Cypress test files.
Key changes included:
calendarUtils.ts: ImportedCalendarResponseandVEventtypes from node-ical, createdCalendarEventInfointerfacegetStaticMarkdownProps.ts: AddedPropsinterface for type-safe parameter handlinggetPartsOfJson.ts,getScopesOfParsedJsonSchema.ts,slugifyMarkdownHeadline.ts: Fixed reduce() operations with explicit type annotationsblog/index.page.tsx: Implemented type guards for category filtering with proper type predicatespages/_app.page.tsx,pages/index.page.tsx,community/index.page.tsx: Fixed Frontmatter and data type annotationsType Safety Improvements:
Does this PR introduce a breaking change?
No
Checklist
Please ensure the following tasks are completed before submitting this pull request.