Skip to content

Conversation

@vtushar06
Copy link
Contributor

@vtushar06 vtushar06 commented Dec 7, 2025

What kind of change does this PR introduce?
This PR introduces centralized type definitions to eliminate 'any' type annotations across the codebase.

Issue Number:

Summary

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:

  • Created types/common.ts with shared type definitions: Frontmatter, SectionType, NavLink, Author
  • Updated 24 page components to import and use the Frontmatter type instead of 'any'
  • Fixed DocTable.tsx to accept optional frontmatter properties with proper type guards and conditional rendering
  • Pages updated: all draft versions (05-07, 2019-09, 2020-12), implementers, learn, overview, specification, understanding-json-schema, ambassadors

Type Safety Improvements:

  • Ensures consistent frontmatter handling across all markdown-based pages
  • Eliminates implicit 'any' typing in static page generation
  • Provides IDE autocomplete and type checking for frontmatter properties

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.

  • Read, understood, and followed the contributing guidelines.
  • TypeScript compilation: 0 errors
  • Linting passes with no warnings
  • All 26 pages tested and verified

Copilot AI review requested due to automatic review settings December 7, 2025 03:14
@vtushar06 vtushar06 requested a review from a team as a code owner December 7, 2025 03:14
@github-project-automation github-project-automation bot moved this to Ready to review in PR - Triage Group Dec 7, 2025
Copy link

Copilot AI left a 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.ts with 10+ reusable type definitions for consistent typing across the application
  • Updated 26 page components to use the Frontmatter type 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.

Comment on lines +32 to +34
Specification?: string;
Published?: string;
Metaschema?: string;
Copy link

Copilot AI Dec 7, 2025

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:

  1. The Specification, Published, and Metaschema properties are marked as optional, but the DocTable component (line 53) requires them to be non-null strings and accesses them without null checks.
  2. The authors property is inherited as authors?: Author[] from Frontmatter, but DocTable expects authors: string[].

Consider either:

  • Making Specification, Published, and Metaschema required (non-optional) in the interface
  • Adding authors?: string[]; to override the base type
    Or update the DocTable component to handle optional values properly.
Suggested change
Specification?: string;
Published?: string;
Metaschema?: string;
Specification: string;
Published: string;
Metaschema: string;
authors?: string[];

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +31
interface DraftFrontmatter extends Frontmatter {
Specification?: string;
Published?: string;
Metaschema?: string;
Copy link

Copilot AI Dec 7, 2025

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:

  1. The Specification, Published, and Metaschema properties are marked as optional, but the DocTable component (line 50) requires them to be non-null strings and accesses them without null checks.
  2. The authors property is inherited as authors?: Author[] from Frontmatter, but DocTable expects authors: string[].

Consider either:

  • Making Specification, Published, and Metaschema required (non-optional) in the interface
  • Adding authors?: string[]; to override the base type
    Or update the DocTable component to handle optional values properly.
Suggested change
interface DraftFrontmatter extends Frontmatter {
Specification?: string;
Published?: string;
Metaschema?: string;
interface DraftFrontmatter extends Omit<Frontmatter, 'authors'> {
Specification: string;
Published: string;
Metaschema: string;
authors: string[];

Copilot uses AI. Check for mistakes.
Comment on lines +29 to +31
Specification?: string;
Published?: string;
Metaschema?: string;
Copy link

Copilot AI Dec 7, 2025

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:

  1. The Specification, Published, and Metaschema properties are marked as optional, but the DocTable component (line 50) requires them to be non-null strings and accesses them without null checks.
  2. The authors property is inherited as authors?: Author[] from Frontmatter, but DocTable expects authors: string[].

Consider either:

  • Making Specification, Published, and Metaschema required (non-optional) in the interface
  • Adding authors?: string[]; to override the base type
    Or update the DocTable component to handle optional values properly.
Suggested change
Specification?: string;
Published?: string;
Metaschema?: string;
Specification: string;
Published: string;
Metaschema: string;
authors?: string[];

Copilot uses AI. Check for mistakes.
<Headline1>{frontmatter.title}</Headline1>
<h1>{frontmatter.type}</h1>
<h2>{frontmatter.Specification}</h2>
{frontmatter.type && <h1>{frontmatter.type}</h1>}
Copy link

Copilot AI Dec 7, 2025

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.

Suggested change
{frontmatter.type && <h1>{frontmatter.type}</h1>}
{frontmatter.type && (
<h1>
{Array.isArray(frontmatter.type)
? frontmatter.type.join(', ')
: frontmatter.type}
</h1>
)}

Copilot uses AI. Check for mistakes.
Comment on lines +76 to +86
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;
Copy link

Copilot AI Dec 7, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +31
export interface StaticPropsParams {
params?: {
slug: string;
};
}
Copy link

Copilot AI Dec 7, 2025

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.

Suggested change
export interface StaticPropsParams {
params?: {
slug: string;
};
}

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +32
Specification?: string;
Published?: string;
Metaschema?: string;
Copy link

Copilot AI Dec 7, 2025

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:

  1. The Specification, Published, and Metaschema properties are marked as optional, but the DocTable component (line 50) requires them to be non-null strings and accesses them without null checks.
  2. The authors property is inherited as authors?: Author[] from Frontmatter, but DocTable expects authors: string[].

Consider either:

  • Making Specification, Published, and Metaschema required (non-optional) in the interface
  • Adding authors?: string[]; to override the base type
    Or update the DocTable component to handle optional values properly.
Suggested change
Specification?: string;
Published?: string;
Metaschema?: string;
Specification: string;
Published: string;
Metaschema: string;
authors?: string[];

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +32
Specification?: string;
Published?: string;
Metaschema?: string;
Copy link

Copilot AI Dec 7, 2025

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:

  1. The Specification, Published, and Metaschema properties are marked as optional, but the DocTable component (line 50) requires them to be non-null strings and accesses them without null checks.
  2. The authors property is inherited as authors?: Author[] from Frontmatter, but DocTable expects authors: string[].

Consider either:

  • Making Specification, Published, and Metaschema required (non-optional) in the interface
  • Adding authors?: string[]; to override the base type
    Or update the DocTable component to handle optional values properly.
Suggested change
Specification?: string;
Published?: string;
Metaschema?: string;
Specification: string;
Published: string;
Metaschema: string;
authors?: string[];

Copilot uses AI. Check for mistakes.
@vtushar06 vtushar06 force-pushed the fix/remove-any-types-pr1-types-and-pages branch from 439866b to f8f90bc Compare December 7, 2025 03:25
@github-actions
Copy link

github-actions bot commented Dec 7, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
website ✅ Ready (View Log) Visit Preview 1ff4ed9

@codecov
Copy link

codecov bot commented Dec 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2dd1d24) to head (1ff4ed9).
⚠️ Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vtushar06 vtushar06 changed the title fix: Remove 'any' types by centralizing type definitions fix(types): Remove 'any' types by centralizing type definitions (#1034) Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready to review

Development

Successfully merging this pull request may close these issues.

🐛 Bug: Search and remove any from codebase

1 participant