-
-
Notifications
You must be signed in to change notification settings - Fork 358
fix(types): Remove 'any' types by centralizing type definitions (#1034) #1973
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(types): Remove 'any' types by centralizing type definitions (#1034) #1973
Conversation
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 enhances type safety across the JSON Schema website by introducing a centralized type definition system that replaces 'any' type annotations with properly typed interfaces. A new types/common.ts file consolidates shared type definitions including Frontmatter, SectionType, NavLink, Author, and other reusable types.
Key changes:
- Created
types/common.tswith 10+ reusable type definitions for consistent typing across the application - Updated 26 page components to use the
Frontmattertype instead of 'any', improving IDE support and compile-time type checking - Standardized the use of nullish coalescing operator (
??) for more precise null/undefined handling in section context providers
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
types/common.ts |
New centralized type definition file with Frontmatter, SectionType, NavLink, Author, and other shared interfaces |
pages/understanding-json-schema/reference/[slug].page.tsx |
Replaced 'any' types with Frontmatter and proper parameter types; improved null handling with ?? operator |
pages/understanding-json-schema/index.page.tsx |
Removed unused parameters and changed blocks from any[] to string[] |
pages/understanding-json-schema/[slug].page.tsx |
Added Frontmatter type import and replaced 'any' with proper types; standardized null handling |
pages/specification/release-notes/index.page.tsx |
Introduced BlocksData interface and replaced 'any' with Frontmatter; added conditional rendering for optional body |
pages/specification/migration/index.page.tsx |
Added typed interfaces for blocks and frontmatter; improved optional field handling |
pages/specification/json-hyper-schema/index.page.tsx |
Extended Frontmatter with SpecificationFrontmatter; added conditional rendering for optional fields |
pages/overview/sponsors/index.page.tsx |
Changed blocks type from any[] to string[] |
pages/overview/code-of-conduct/index.page.tsx |
Removed unused parameters and improved type safety for blocks |
pages/overview/[slug].page.tsx |
Replaced 'any' types with Frontmatter; improved optional chaining for navigation properties |
pages/learn/getting-started-step-by-step/index.page.tsx |
Removed unused parameters; typed blocks as string[] |
pages/learn/[slug].page.tsx |
Added proper types for frontmatter and content; standardized null handling |
pages/implementers/index.page.tsx |
Cleaned up unused parameters and improved blocks typing |
pages/implementers/[slug].page.tsx |
Replaced 'any' with Frontmatter type; standardized section context handling |
pages/draft/2020-12/index.page.tsx |
Extended Frontmatter with DraftFrontmatter for draft-specific fields |
pages/draft/2020-12/[slug].page.tsx |
Improved type safety with Frontmatter type and proper parameter typing |
pages/draft/2019-09/index.page.tsx |
Added DraftFrontmatter and BlocksData interfaces for type safety |
pages/draft/2019-09/[slug].page.tsx |
Replaced 'any' types with proper TypeScript types |
pages/draft-07/index.page.tsx |
Introduced typed interfaces for draft frontmatter and blocks data |
pages/draft-07/[slug].page.tsx |
Added Frontmatter type and improved null handling |
pages/draft-06/index.page.tsx |
Added draft-specific type extensions and improved type safety |
pages/draft-06/[slug].page.tsx |
Replaced 'any' with Frontmatter and standardized section handling |
pages/draft-05/index.page.tsx |
Extended Frontmatter for draft-specific metadata fields |
pages/ambassadors/index.page.tsx |
Changed ambassadorData from any to string type |
pages/[slug].page.tsx |
Added type import and replaced 'any' with proper Frontmatter and string types |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Specification?: string; | ||
| Published?: string; | ||
| Metaschema?: string; |
Copilot
AI
Dec 7, 2025
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.
Type safety issues with DraftFrontmatter:
- The
Specification,Published, andMetaschemaproperties are marked as optional, but theDocTablecomponent (line 53) requires them to be non-null strings and accesses them without null checks. - The
authorsproperty is inherited asauthors?: Author[]fromFrontmatter, butDocTableexpectsauthors: string[].
Consider either:
- Making
Specification,Published, andMetaschemarequired (non-optional) in the interface - Adding
authors?: string[];to override the base type
Or update theDocTablecomponent to handle optional values properly.
| Specification?: string; | |
| Published?: string; | |
| Metaschema?: string; | |
| Specification: string; | |
| Published: string; | |
| Metaschema: string; | |
| authors?: string[]; |
| interface DraftFrontmatter extends Frontmatter { | ||
| Specification?: string; | ||
| Published?: string; | ||
| Metaschema?: string; |
Copilot
AI
Dec 7, 2025
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.
Type safety issues with DraftFrontmatter:
- The
Specification,Published, andMetaschemaproperties are marked as optional, but theDocTablecomponent (line 50) requires them to be non-null strings and accesses them without null checks. - The
authorsproperty is inherited asauthors?: Author[]fromFrontmatter, butDocTableexpectsauthors: string[].
Consider either:
- Making
Specification,Published, andMetaschemarequired (non-optional) in the interface - Adding
authors?: string[];to override the base type
Or update theDocTablecomponent to handle optional values properly.
| interface DraftFrontmatter extends Frontmatter { | |
| Specification?: string; | |
| Published?: string; | |
| Metaschema?: string; | |
| interface DraftFrontmatter extends Omit<Frontmatter, 'authors'> { | |
| Specification: string; | |
| Published: string; | |
| Metaschema: string; | |
| authors: string[]; |
| Specification?: string; | ||
| Published?: string; | ||
| Metaschema?: string; |
Copilot
AI
Dec 7, 2025
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.
Type safety issues with DraftFrontmatter:
- The
Specification,Published, andMetaschemaproperties are marked as optional, but theDocTablecomponent (line 50) requires them to be non-null strings and accesses them without null checks. - The
authorsproperty is inherited asauthors?: Author[]fromFrontmatter, butDocTableexpectsauthors: string[].
Consider either:
- Making
Specification,Published, andMetaschemarequired (non-optional) in the interface - Adding
authors?: string[];to override the base type
Or update theDocTablecomponent to handle optional values properly.
| Specification?: string; | |
| Published?: string; | |
| Metaschema?: string; | |
| Specification: string; | |
| Published: string; | |
| Metaschema: string; | |
| authors?: string[]; |
| <Headline1>{frontmatter.title}</Headline1> | ||
| <h1>{frontmatter.type}</h1> | ||
| <h2>{frontmatter.Specification}</h2> | ||
| {frontmatter.type && <h1>{frontmatter.type}</h1>} |
Copilot
AI
Dec 7, 2025
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.
Potential rendering issue: The frontmatter.type property can be either string | string[] according to the Frontmatter interface. If type is an array, rendering it directly in the <h1> tag will display it as a comma-separated string (e.g., "type1,type2"), which may not be the intended display format. Consider handling arrays explicitly with .join() or rendering only the first value if this is not the expected behavior.
| {frontmatter.type && <h1>{frontmatter.type}</h1>} | |
| {frontmatter.type && ( | |
| <h1> | |
| {Array.isArray(frontmatter.type) | |
| ? frontmatter.type.join(', ') | |
| : frontmatter.type} | |
| </h1> | |
| )} |
| export interface SlateRenderProps { | ||
| attributes: { | ||
| 'data-slate-node'?: string; | ||
| 'data-slate-inline'?: boolean; | ||
| 'data-slate-void'?: boolean; | ||
| dir?: 'rtl'; | ||
| ref: React.RefObject<HTMLElement>; | ||
| [key: string]: unknown; | ||
| }; | ||
| children: React.ReactNode; |
Copilot
AI
Dec 7, 2025
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.
Missing import: The file uses React.RefObject<HTMLElement> and React.ReactNode but doesn't import React. Add import React from 'react'; at the top of the file to ensure TypeScript can resolve these types.
| export interface StaticPropsParams { | ||
| params?: { | ||
| slug: string; | ||
| }; | ||
| } |
Copilot
AI
Dec 7, 2025
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.
[nitpick] The StaticPropsParams interface is defined but not used in any of the updated page components. All pages use inline type { params?: { slug: string } } instead. Consider either using this interface consistently across pages (e.g., export async function getStaticProps(args: StaticPropsParams)) or removing it if it's not needed.
| export interface StaticPropsParams { | |
| params?: { | |
| slug: string; | |
| }; | |
| } |
| Specification?: string; | ||
| Published?: string; | ||
| Metaschema?: string; |
Copilot
AI
Dec 7, 2025
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.
Type safety issues with DraftFrontmatter:
- The
Specification,Published, andMetaschemaproperties are marked as optional, but theDocTablecomponent (line 50) requires them to be non-null strings and accesses them without null checks. - The
authorsproperty is inherited asauthors?: Author[]fromFrontmatter, butDocTableexpectsauthors: string[].
Consider either:
- Making
Specification,Published, andMetaschemarequired (non-optional) in the interface - Adding
authors?: string[];to override the base type
Or update theDocTablecomponent to handle optional values properly.
| Specification?: string; | |
| Published?: string; | |
| Metaschema?: string; | |
| Specification: string; | |
| Published: string; | |
| Metaschema: string; | |
| authors?: string[]; |
| Specification?: string; | ||
| Published?: string; | ||
| Metaschema?: string; |
Copilot
AI
Dec 7, 2025
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.
Type safety issues with DraftFrontmatter:
- The
Specification,Published, andMetaschemaproperties are marked as optional, but theDocTablecomponent (line 50) requires them to be non-null strings and accesses them without null checks. - The
authorsproperty is inherited asauthors?: Author[]fromFrontmatter, butDocTableexpectsauthors: string[].
Consider either:
- Making
Specification,Published, andMetaschemarequired (non-optional) in the interface - Adding
authors?: string[];to override the base type
Or update theDocTablecomponent to handle optional values properly.
| Specification?: string; | |
| Published?: string; | |
| Metaschema?: string; | |
| Specification: string; | |
| Published: string; | |
| Metaschema: string; | |
| authors?: string[]; |
439866b to
f8f90bc
Compare
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 #1973 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 30 30
Lines 633 644 +11
Branches 196 206 +10
=========================================
+ Hits 633 644 +11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
f8f90bc to
1ff4ed9
Compare
What kind of change does this PR introduce?
This PR introduces centralized type definitions to eliminate 'any' type annotations across the codebase.
Issue Number:
anyfrom codebase #1034Summary
This PR improves type safety by introducing a centralized type definition system (
types/common.ts) that replaces scattered 'any' type usages across 26 files.Key changes included:
types/common.tswith shared type definitions:Frontmatter,SectionType,NavLink,AuthorFrontmattertype instead of 'any'DocTable.tsxto accept optional frontmatter properties with proper type guards and conditional renderingType Safety Improvements:
Does this PR introduce a breaking change?
No. This is a pure refactoring that improves type safety without changing functionality.
Checklist
Please ensure the following tasks are completed before submitting this pull request.