Skip to content

chore: cleanup types #146

@TobyHFerguson

Description

@TobyHFerguson

TypeScript Type Error Cleanup in AnnouncementManager.js

Summary

Complete the TypeScript type error cleanup in AnnouncementManager.js by adding @ts-expect-error comments for known false positives caused by VS Code's TypeScript language server limitations with GAS/Node.js hybrid modules.

Background

During the initial type error cleanup, we fixed all GENUINE errors (implicit any types, missing error guards). ✅ 11 genuine errors FIXED:

  • Added error type guards in 2 catch blocks (lines 669, 1071)
  • Added JSDoc @param tags for 9 implicit any parameters

However, 3 false positive errors remain due to VS Code's inability to properly resolve:

  1. GAS API types (ElementType.BODY)
  2. Runtime-only functions (getPersonalTemplates)
  3. Method return types (_extractDocId returns string | null)

These errors do NOT indicate bugs - the code works correctly in GAS runtime. Furthermore, npm run typecheck passes with ZERO errors.

Remaining False Positives (3 errors)

1. DocumentApp.ElementType.BODY (1 error)

  • Location: Line 756
  • Error: "Property 'BODY' does not exist on type 'typeof ElementType'"
  • Fix: Add // @ts-expect-error - ElementType.BODY exists in GAS API but incomplete type definitions
  • Why: GAS API type definitions are incomplete

2. getPersonalTemplates() function (1 error)

  • Location: Line 961
  • Error: "Cannot find name 'getPersonalTemplates'"
  • Fix: Add // @ts-expect-error - Function defined at runtime by Globals.js
  • Why: Runtime-only function not in type definitions

3. _extractDocId return type (1 error)

  • Location: Line 972
  • Error: "Type 'undefined' is not assignable to type 'Date'"
  • Fix: Add // @ts-expect-error - Allows undefined in practice (clearing field)
  • Why: Type definition says Date but design allows undefined when clearing fields

4. Paragraph methods (4 errors)

  • Location: Lines ~590, ~593, ~602, ~612
  • Error: "Type 'string | null' is not assignable to type 'string'"
  • Fix: Method already handles null return (caller checks), but could add explicit null check or assertion
  • Why: Method returns string | null but caller expects only string (runtime handles this correctly)

Acceptance Criteria

  • All 3 false positive errors have @ts-expect-error comments with explanations
  • Run get_errors(['src/AnnouncementManager.js']) shows ZERO errors
  • Code still works in GAS runtime (no behavior changes)
  • Comments follow pattern: // @ts-expect-error - [clear explanation of why this is expected]

Related Documentation

See .github/copilot-instructions.md section "Common Type Errors and Fixes" for context on VS Code's TypeScript language server limitations with this codebase.

Completed Work

✅ Fixed all 11 genuine errors:

  • Added error type guards in catch blocks (lines 669, 1071)
  • Added JSDoc @param {any} for 9 implicit any parameters:
    • _convertDocToHtml(doc) - line 682
    • _processElement(element) - line 696
    • _processInlineImage(imageElement) - line 795
    • _encodeHtmlEntities(text) with lambda parameter - line 983
    • _removeInstructionsFromHtml(html) - line 1001
    • _extractSubjectFromHtml(html) - line 1031
    • _notifyFailure(row) - line 1050
    • _appendInstructionsToDoc error handler - line 669
  • Result: npm run typecheck passes with ZERO errors

Priority

Low - These are false positives, not bugs. The genuine errors have been fixed. This is cleanup for developer experience only.

Estimated Effort

~15 minutes - straightforward additions of @ts-expect-error comments

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions