-
Notifications
You must be signed in to change notification settings - Fork 126
Open
Milestone
Description
Summary
Adopt TypeScript for the JavaScript codebase to improve type safety, IDE support, and catch errors at compile time. Now that we have a proper build system with webpack, TypeScript integration is straightforward.
Benefits
- Catch errors early - Type mismatches caught at build time, not runtime
- Better IDE support - Autocomplete, refactoring, go-to-definition
- Self-documenting - Types serve as inline documentation
- Safer refactoring - Compiler catches breaking changes
- Better React props - Replace PropTypes with interfaces (smaller bundle)
Example
// Before: JavaScript with PropTypes
const Entry = ({ id, content, authors }) => { /* ... */ };
Entry.propTypes = {
id: PropTypes.number.isRequired,
content: PropTypes.string.isRequired,
authors: PropTypes.arrayOf(PropTypes.object),
};
// After: TypeScript
interface Author {
id: number;
name: string;
avatar?: string;
}
interface EntryProps {
id: number;
content: string;
authors: Author[];
}
const Entry: React.FC<EntryProps> = ({ id, content, authors }) => { /* ... */ };Migration Strategy
Phase 1: Setup (1 day)
- Install TypeScript:
npm install -D typescript @types/react @types/react-dom - Configure
tsconfig.jsonwithallowJs: truefor gradual adoption - Update webpack to handle
.ts/.tsxfiles
Phase 2: Type Definitions (1 week)
- Create types for Redux state shape
- Create types for API responses
- Create types for WordPress globals (
window.liveblog_settings)
Phase 3: Gradual Migration
- Rename files
.js→.tsxone at a time - Start with utility functions (low risk)
- Then reducers and actions
- Then components (simpler first)
- Enable stricter options incrementally
Phase 4: Cleanup
- Remove
prop-typesdependency - Enable
strict: truein tsconfig - Add type coverage reporting to CI
Considerations
- Learning curve - Team needs TypeScript familiarity
- Build time - Slightly slower builds (minimal with modern tooling)
- Third-party types - Most libraries have types, but some may need
@types/*packages - Gradual adoption - Can coexist with JavaScript during migration
Configuration
// tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"lib": ["ES2020", "DOM"],
"jsx": "react-jsx",
"allowJs": true,
"checkJs": false,
"strict": false,
"esModuleInterop": true,
"skipLibCheck": true,
"outDir": "./build",
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "build"]
}Success Metrics
- TypeScript configured and building
- Core types defined (Entry, Author, Config, State)
- New code written in TypeScript
- 50%+ of existing code migrated
- PropTypes dependency removed
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels