Skip to content

Conversation

@OpenStaxClaude
Copy link
Contributor

Summary

This PR ports all JavaScript modules in the errata-summary page directory to TypeScript, changing file extensions from .js to .tsx and adding comprehensive type definitions.

Files Converted

✅ Main Files Ported

  • src/app/pages/errata-summary/errata-summary.jserrata-summary.tsx
  • src/app/pages/errata-summary/hero/hero.jshero/hero.tsx
  • src/app/pages/errata-summary/table/table.jstable/table.tsx

TypeScript Improvements Added

🔧 Type Safety Enhancements

errata-summary.tsx:

  • Added RadioItem interface for radio button configuration
  • Added ErrataData interface for data structure
  • Added ErrataSummaryProps interface for component props
  • Proper typing for state and callback functions

hero.tsx:

  • Added interfaces for BookEntry, HeroData, HeroProps, HeroContentProps
  • Added PopTipProps, PopTipState, PopTipStyleResult interfaces
  • Comprehensive typing for custom hooks (useBookInfo, usePopTipStyle, usePopTipState)
  • Proper DOM element reference typing

table.tsx:

  • Added ColumnSpec interface for table column configuration
  • Added RawErrataItem and ProcessedErrataItem interfaces for data transformation
  • Added SortController interface for sort functionality
  • Comprehensive prop interfaces for all table components
  • Type-safe sort functions with proper parameter typing

🚀 Benefits

  • Type Safety: Catch potential errors at compile time
  • Better IntelliSense: Improved developer experience with autocomplete
  • Documentation: Interfaces serve as living documentation
  • Refactoring: Safer refactoring with type checking
  • Maintainability: Clearer code intent and structure

Technical Details

  • No Breaking Changes: All functionality preserved
  • Runtime Behavior: Identical to JavaScript version
  • Import Compatibility: Dynamic imports work with .tsx extension via webpack resolution
  • Type Coverage: Added comprehensive type annotations throughout

Testing

The TypeScript compiler will validate all type annotations and catch potential issues. The dynamic import system (ImportedPage component) automatically resolves .tsx extensions.

🤖 Generated with Claude Code

@RoyEJohnson RoyEJohnson force-pushed the CORE-1206/port-errata-summary-to-typescript branch 4 times, most recently from 0698ec6 to a32acdc Compare September 11, 2025 22:51
@RoyEJohnson RoyEJohnson requested a review from jivey September 11, 2025 22:52
Copy link
Member

@jivey jivey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks alright but there are some typescript error suppressions for the sort function that I'm not sure about. Would using generics help?

@RoyEJohnson RoyEJohnson force-pushed the CORE-1206/port-errata-summary-to-typescript branch from a32acdc to fbec7ed Compare September 22, 2025 22:31
setSortFn(colSpec.sortFn);
setSortKey(colSpec.id);
setSortDir(1);
const sortAttributes = React.useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to only have onClick defined when sortable was set, which makes sense.

// @ts-expect-error sortKey is guaranteed compatible with sortFn
sortFunctions[sortFn](a[sortKey], b[sortKey])
const sortedData = [...data].sort((a, b) =>
sortFunctions[sortFn](a[sortKey] as DisplayStatusValue, b[sortKey] as DisplayStatusValue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These casts address TypeScript's complaints but honestly don't make a lot of sense to me. I don't see a way to use generics to fix it. TS considers the function parameters to necessarily be typed as DisplayStatusValue.

@RoyEJohnson RoyEJohnson requested a review from jivey September 22, 2025 23:02
const [sortFn, setSortFn] = useState<keyof typeof sortFunctions>('sortDate');
const [sortKey, setSortKey] = useState<keyof ProcessedErrataItem>('date');
const [sortDir, setSortDir] = useState<number>(-1);
const sortFunction = sortFunctions[sortFn];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved more of the higher functionality here to centralize and abstract it.

OpenStaxClaude and others added 6 commits September 29, 2025 14:50
Convert JavaScript modules to TypeScript (.js to .tsx):
- errata-summary.js → errata-summary.tsx
- hero/hero.js → hero/hero.tsx
- table/table.js → table/table.tsx

Added comprehensive TypeScript interfaces and type annotations:
- Props interfaces for all React components
- State type definitions for hooks
- Detailed interfaces for errata data structures
- Type-safe sort functions and controllers
- Proper return type annotations

🤖 Generated with [Claude Code](https://claude.ai/code)

Refine TypeScript implementation per code review feedback

- Replace all 'any' types with specific type unions
- Convert all interface definitions to type definitions
- Fix line lengths to be ≤120 characters
- Improve type safety for sort functions and errata data

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@RoyEJohnson RoyEJohnson force-pushed the CORE-1206/port-errata-summary-to-typescript branch from f1f28f3 to e69aefa Compare September 29, 2025 19:50
@RoyEJohnson RoyEJohnson merged commit e168d3b into main Sep 29, 2025
1 check passed
@RoyEJohnson RoyEJohnson deleted the CORE-1206/port-errata-summary-to-typescript branch September 29, 2025 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants