|
| 1 | +--- |
| 2 | +name: Add TypeScript Definitions for All Modules |
| 3 | +about: Track technical debt for missing TypeScript definition files across the codebase |
| 4 | +title: 'Add TypeScript definitions (.d.ts) for all modules to prevent API mismatches' |
| 5 | +labels: technical-debt, enhancement, typescript |
| 6 | +assignees: '' |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## Problem Statement |
| 11 | + |
| 12 | +During RetryQueue testing, we encountered **14+ runtime errors** caused by API mismatches that TypeScript definitions would have caught at development time: |
| 13 | +- `schedule.getLastRow()` vs `loadLastRow()` |
| 14 | +- `_rowNum` vs `rowNum` |
| 15 | +- Static method calls on class requiring instantiation |
| 16 | +- Method name mismatches (`getQueueStatus()` vs `getStatus()`) |
| 17 | +- Property name errors (`nextRetry` vs `nextRetryAt`) |
| 18 | + |
| 19 | +**Current Coverage**: Only 9 modules have `.d.ts` files: |
| 20 | +- ✅ Event.d.ts |
| 21 | +- ✅ EventFactory.d.ts |
| 22 | +- ✅ Externals.d.ts |
| 23 | +- ✅ Globals.d.ts |
| 24 | +- ✅ GoogleCalendarManager.d.ts |
| 25 | +- ✅ Groups.d.ts |
| 26 | +- ✅ MenuFunctions.d.ts |
| 27 | +- ✅ RideManager.d.ts |
| 28 | +- ✅ UIManager.d.ts |
| 29 | + |
| 30 | +**Missing Coverage**: ~30+ modules lack TypeScript definitions, including critical infrastructure: |
| 31 | +- ❌ ScheduleAdapter.js |
| 32 | +- ❌ Row.js |
| 33 | +- ❌ Commands.js |
| 34 | +- ❌ ProcessingManager.js |
| 35 | +- ❌ rowCheck.js |
| 36 | +- ❌ HyperlinkUtils.js |
| 37 | +- ❌ RouteColumnEditor.js |
| 38 | +- ❌ UserLogger.js |
| 39 | +- ❌ And many more... |
| 40 | + |
| 41 | +## Business Impact |
| 42 | + |
| 43 | +**Development Velocity**: Every API mismatch requires: |
| 44 | +1. User encounters runtime error in GAS |
| 45 | +2. Developer investigates error logs |
| 46 | +3. Find actual API signature |
| 47 | +4. Fix code |
| 48 | +5. Push to GAS |
| 49 | +6. User re-tests |
| 50 | + |
| 51 | +This cycle repeats for each error, wasting significant time. |
| 52 | + |
| 53 | +**Code Quality**: TypeScript definitions provide: |
| 54 | +- Auto-completion in VS Code |
| 55 | +- Type checking before deployment |
| 56 | +- Self-documenting APIs |
| 57 | +- Refactoring confidence |
| 58 | + |
| 59 | +## Technical Requirements |
| 60 | + |
| 61 | +### Phase 1: Critical Infrastructure (Priority: HIGH) |
| 62 | +Create `.d.ts` files for modules with complex APIs or frequent usage: |
| 63 | + |
| 64 | +1. **ScheduleAdapter.d.ts** - Complex spreadsheet I/O |
| 65 | +2. **Row.d.ts** - Data model with many properties |
| 66 | +3. **Commands.d.ts** - Command pattern interface |
| 67 | + |
| 68 | +### Phase 2: Business Logic (Priority: MEDIUM) |
| 69 | +6. **ProcessingManager.d.ts** |
| 70 | +7. **rowCheck.d.ts** - Validation functions |
| 71 | +8. **HyperlinkUtils.d.ts** |
| 72 | +9. **RouteColumnEditor.d.ts** |
| 73 | + |
| 74 | +### Phase 3: Supporting Modules (Priority: LOW) |
| 75 | +11. **UserLogger.d.ts** |
| 76 | +12. **utils.d.ts** |
| 77 | +13. **testEvent.d.ts** |
| 78 | +14. All remaining modules |
| 79 | + |
| 80 | +## Architecture Guidelines |
| 81 | + |
| 82 | +Following `.github/copilot-instructions.md` patterns: |
| 83 | + |
| 84 | +### For Pure JavaScript Modules (*Core.js) |
| 85 | +```typescript |
| 86 | +/** |
| 87 | + * Pure JavaScript module - no GAS dependencies |
| 88 | + * Can be tested in Jest with 100% coverage |
| 89 | + */ |
| 90 | +declare class ModuleName { |
| 91 | + static method(param: Type): ReturnType; |
| 92 | +} |
| 93 | + |
| 94 | +export = ModuleName; |
| 95 | +``` |
| 96 | + |
| 97 | +### For GAS Adapter Modules |
| 98 | +```typescript |
| 99 | +/** |
| 100 | + * GAS-specific adapter - thin wrapper around Core logic |
| 101 | + */ |
| 102 | +declare class ModuleName { |
| 103 | + constructor(); |
| 104 | + method(param: Type): ReturnType; |
| 105 | + private _gasSpecificMethod(): void; |
| 106 | +} |
| 107 | + |
| 108 | +export = ModuleName; |
| 109 | +``` |
| 110 | + |
| 111 | +### For Frozen Command Objects |
| 112 | +```typescript |
| 113 | +interface Command { |
| 114 | + readonly name: string; |
| 115 | + readonly execute: (rows: Row[], rwgps: any, force: boolean) => void; |
| 116 | +} |
| 117 | + |
| 118 | +declare const Commands: { |
| 119 | + readonly commandName: Command; |
| 120 | +}; |
| 121 | + |
| 122 | +export = Commands; |
| 123 | +``` |
| 124 | + |
| 125 | +## Acceptance Criteria |
| 126 | + |
| 127 | +- [ ] All Phase 1 modules have `.d.ts` files |
| 128 | +- [ ] TypeScript checking enabled in VS Code workspace |
| 129 | +- [ ] JSDoc comments enhanced to support TypeScript inference |
| 130 | +- [ ] `jsconfig.json` configured for type checking |
| 131 | +- [ ] Documentation updated with TypeScript examples |
| 132 | +- [ ] CI/CD pipeline validates TypeScript definitions (if applicable) |
| 133 | + |
| 134 | +## Testing Strategy |
| 135 | + |
| 136 | +1. Create `.d.ts` file |
| 137 | +2. Add `// @ts-check` to corresponding `.js` file |
| 138 | +3. Verify VS Code shows type errors for known issues |
| 139 | +4. Fix any discovered type mismatches |
| 140 | +5. Remove `// @ts-check` after validation (optional, based on team preference) |
| 141 | + |
| 142 | +## Related Issues |
| 143 | + |
| 144 | +- Blocked by: None |
| 145 | +- Blocks: Future refactoring work |
| 146 | + |
| 147 | +## Estimated Effort |
| 148 | + |
| 149 | +- Phase 1 (5 modules): ~8 hours |
| 150 | +- Phase 2 (5 modules): ~6 hours |
| 151 | +- Phase 3 (remaining): ~10 hours |
| 152 | +- **Total**: ~24 hours (3 days) |
| 153 | + |
| 154 | +## Benefits |
| 155 | + |
| 156 | +✅ **Prevent runtime errors** - Catch API mismatches at development time |
| 157 | +✅ **Improve developer experience** - Auto-completion and inline documentation |
| 158 | +✅ **Enable safer refactoring** - Type checking during code changes |
| 159 | +✅ **Self-documenting code** - Types serve as executable documentation |
| 160 | +✅ **Reduce debugging time** - Fix issues before deployment |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +**Note**: This is technical debt from the original GAS-first development approach. Adding TypeScript definitions incrementally will modernize the codebase without requiring a full rewrite. |
0 commit comments