Migrate to TypeScript
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, rails, react, redux, typescript
- Domain
- build-system, documentation, frontend, testing, tooling
Research direction
Start by inspecting package.json, the Shakapacker configuration, and the client/app directory to understand the current JavaScript and React structure. Then review the proposed tsconfig.json and ESLint setup, and identify a bounded migration phase. Done means the selected scope type-checks, builds and tests pass, CI runs TypeScript checking, and the relevant documentation is updated.
Written by the indexing model from the issue text.
Description
Background
This tutorial currently uses JavaScript. Migrating to TypeScript would provide better type safety, improved IDE support, and catch more errors at compile time.
Benefits of TypeScript
- Type safety: Catch type-related bugs at compile time
- Better IDE support: Enhanced autocomplete, refactoring, and navigation
- Self-documenting code: Types serve as inline documentation
- Easier refactoring: Compiler helps identify breaking changes
- Modern standard: TypeScript is increasingly the standard for React applications
Migration Plan
1. Initial Setup
- Add TypeScript dependencies to
package.json:typescript@types/react@types/react-dom@types/node- Other
@types/*packages for existing dependencies
- Create
tsconfig.jsonwith appropriate compiler options - Update Shakapacker configuration to handle
.tsand.tsxfiles - Configure ESLint to work with TypeScript (
@typescript-eslint/parser,@typescript-eslint/eslint-plugin)
2. tsconfig.json Example
{
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"jsx": "react-jsx",
"module": "ESNext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"allowJs": true,
"checkJs": false,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"*": ["client/app/*"]
}
},
"include": ["client/app/**/*"],
"exclude": ["node_modules", "public", "vendor"]
}
3. Gradual Migration Strategy
- Start with new files in TypeScript
- Migrate simple components first (presentational components)
- Gradually migrate container components
- Migrate utility files and helpers
- Add types for Redux store, actions, and reducers
- Enable stricter TypeScript options incrementally
4. File-by-File Migration Approach
- Rename
.jsxto.tsx(or.jsto.ts) - Add type annotations for props using interfaces
- Add type annotations for state
- Type function parameters and return values
- Fix any TypeScript errors
- Run tests to ensure functionality unchanged
5. Key Areas to Type
- React component props and state
- Redux actions, reducers, and store
- API response types
- Event handlers
- Utility functions
- Constants and enums
6. Testing
- All builds pass with TypeScript enabled
- Type checking passes (
tsc --noEmit) - All existing tests still pass
- IDE provides proper autocomplete and type hints
7. Documentation
- Update README with TypeScript setup instructions
- Document typing conventions and patterns used
- Provide examples of properly typed components
Migration Phases
Phase 1: Setup (Week 1)
- Install dependencies and configure TypeScript
- Set up tooling (ESLint, IDE)
- Create base type definitions
Phase 2: Core Types (Week 2)
- Type Redux store and actions
- Type API responses
- Type common utilities
Phase 3: Component Migration (Weeks 3-4)
- Migrate simple components
- Migrate container components
- Type React Router setup
Phase 4: Refinement (Week 5)
- Enable stricter compiler options
- Add generics where beneficial
- Clean up any
anytypes
Potential Challenges
- Learning curve: Team needs to learn TypeScript
- Migration time: Converting all files takes time
- Third-party types: Some packages may not have good type definitions
- ReScript interop: May need special handling for ReScript components
- Build time: TypeScript checking may slow down builds
References
- TypeScript Documentation
- React TypeScript Cheatsheet
- Shakapacker TypeScript Guide
- Migrating from JS to TS
Acceptance Criteria
- TypeScript configuration is complete
- All builds pass with type checking enabled
- At least 50% of components migrated to TypeScript
- CI includes TypeScript type checking
- Documentation updated
Notes
- This can be done incrementally - TypeScript supports gradual migration
- Start with
strict: falseand enable strict mode features gradually - Use
allowJs: trueto allow mixing.jsand.tsfiles during migration
cc: @justin808
- Dominant language
- JavaScript
- Stars
- 1.7k
- Forks
- 370
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from shakacode/react-webpack-rails-tutorial
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 42/100
shakacode/react-webpack-rails-tutorial#731 · 1 comment ·
-
documentation
Difficulty 4/5 3-5 days Newbie friendliness 50/100
-
question
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 28/100
All issues in shakacode/react-webpack-rails-tutorial
Similar issues
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100