Skip to content

Phase 21 final : Fix remaining typescript errors - #2737

Merged
zanesq merged 8 commits into
fix/typescript-errors-phase19-type-assignmentsfrom
fix/typescript-errors-phase21-possibly-null-undefined
May 30, 2025
Merged

Phase 21 final : Fix remaining typescript errors#2737
zanesq merged 8 commits into
fix/typescript-errors-phase19-type-assignmentsfrom
fix/typescript-errors-phase21-possibly-null-undefined

Conversation

@zanesq

@zanesq zanesq commented May 30, 2025

Copy link
Copy Markdown
Contributor
zane@BLKF6CMQ6NTLW desktop % npm run lint:check

> goose-app@1.0.24 lint:check
> eslint "src/**/*.{ts,tsx}" --max-warnings 0 --no-warn-ignored

=============

WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=4.3.5 <5.4.0

YOUR TYPESCRIPT VERSION: 5.8.3

Please only submit bug reports when using the officially supported version.

=============
zane@BLKF6CMQ6NTLW desktop % npm run typecheck 

> goose-app@1.0.24 typecheck
> tsc --noEmit

Overview

Fixed remaining TypeScript compilation errors in the ui/desktop project and ensured ESLint passes with zero warnings.

Key Changes

Import and Path Fixes

  • CreateScheduleModal.tsx: Fixed import casing from ../ui/select to ../ui/Select
  • ModelRadioList.tsx: Changed @/src/App to relative path ../../../App
  • models/index.ts: Changed @/src/api to relative path ../../../api
  • DefaultProviderSetupForm.tsx: Updated to use proper ProviderDetails and ConfigKey types from API

Type Safety Improvements

  • App.tsx: Fixed unsafe type conversion using as unknown as pattern for SharedSessionDetails
  • SearchView.tsx: Added proper type casting for SearchContainerElement
  • RecipeEditor.tsx: Replaced delete operator with object destructuring to avoid optional property errors
  • utils.tsx: Added type assertions to prevent undefined index access
  • ProviderConfigurationModal.tsx:
    • Changed form values from Record<string, unknown> to Record<string, string>
    • Fixed provider type compatibility issues
    • Added proper type casting for delete operations

Component Fixes

  • ChatView.tsx: Removed unused _RecipeConfig interface
  • ConfigureApproveMode.tsx: Added missing required props (parentView, setView) to ModeSelectionItem
  • CardContainer.tsx: Fixed condition that was always true by removing unnecessary function check

Node.js and Electron Compatibility

  • goosed.ts:
    • Fixed invalid imports (Buffer from node:stream, ProcessEnv from node:process)
    • Added proper Buffer import from node:buffer
    • Created proper interface for environment variables
    • Fixed unref() method call with proper existence check
  • main.ts:
    • Added explicit typing for Electron dialog return values
    • Fixed globalShortcut.register void return type handling
    • Used as unknown as pattern for dialog type casting

Code Quality

  • extension-manager.ts: Fixed uninitialized variable usage
  • SettingsView.tsx & extensions.tsx: Removed unused @ts-expect-error directives
  • RecipeEditor.tsx: Prefixed unused destructured variables with underscore

zanesq added 5 commits May 29, 2025 17:33
- Enhanced input validation in getBinaryPath():
  - Added validation for binary name parameters (length, suspicious chars)
  - Implemented path traversal prevention (block .., /, \)
  - Added command injection prevention (block ;, |, &, `, $)
  - Added file type validation (ensure regular files only)
  - Enhanced path resolution and security checks

- Secured process spawning in startGoosed():
  - Added directory path sanitization and validation
  - Implemented binary path verification with multiple validation layers
  - Added allowed directory enforcement (app/resources/cwd only)
  - Used hardcoded, safe arguments for spawn calls
  - Explicitly disabled shell execution (shell: false)
  - Added file existence and type verification
  - Implemented PID validation for taskkill operations

- Enhanced environment variable security:
  - Added sensitive data redaction in logs (SECRET/PASSWORD/TOKEN)
  - Improved environment isolation and controlled variable passing

- Secured process termination:
  - Added regex validation for process IDs (/^\d+$/)
  - Used validated arguments for all taskkill commands
  - Disabled shell for all spawn operations

Security principles applied:
- Input validation and sanitization
- Path traversal prevention
- Command injection prevention
- Principle of least privilege
- Defense in depth
- Fail secure approach

Resolves command injection vulnerability in child_process.spawn() calls.
- Fixed AddModelModal.tsx formattedModelOptions array typing:
  - Added explicit type annotation for complex nested array structure
  - Type: { options: { value: string; label: string; provider: string }[] }[]

- Fixed main.ts pendingDeepLink variable typing:
  - Changed from implicit any to explicit string | null type
  - Ensures type safety for deep link URL handling

Phase 22 Results:
- TS7005 errors: 6 → 0 (100% elimination)
- Total errors: 51 → 43 (8 errors eliminated)
- Linting: Zero warnings maintained
- Fixed App.tsx unused event parameters (4 fixes):
  - handleOpenSharedSession: event → _event
  - handleFatalError: event → _event
  - handleSetView: event → _event
  - handleAddExtension: event → _event

- Fixed main.ts unused event parameter:
  - context-menu handler: event → _event

- Fixed urlUtils.ts unused parameter:
  - filter callback: url → _url

Technical approach: Used underscore prefix convention to indicate
intentionally unused parameters while maintaining correct function signatures.

Phase 23 Results:
- TS6133 errors: 6 → 0 (100% elimination)
- Total errors: 43 → 37 (6 errors eliminated)
- Linting: Zero warnings maintained
- Progress: 90% reduction (363+ errors eliminated)
- Fixed ConfigureBuiltInExtensionModal.tsx (3 fixes):
  - Changed extension.env_keys?.length > 0 to explicit null check
  - Removed optional chaining in map after null validation
  - Improved TypeScript inference for env_keys access

- Fixed ConfigureExtensionModal.tsx (3 fixes):
  - Applied same pattern for extension.env_keys validation
  - Consistent null safety approach across both modals

Technical approach: Replaced optional chaining with explicit
conditional checks (&&) for better TypeScript inference when
accessing nested properties after validation.

Phase 24 Results:
- TS18048 errors: 6 → 0 (100% elimination)
- Total errors: 37 → 31 (6 errors eliminated)
- Linting: Zero warnings maintained
- Progress: 92% reduction (369+ errors eliminated)
@zanesq
zanesq requested a review from alexhancock May 30, 2025 04:40
Base automatically changed from fix/typescript-errors-phase20-argument-type-mismatches to fix/typescript-errors-phase19-type-assignments May 30, 2025 14:47
@zanesq
zanesq merged commit 48e8a85 into fix/typescript-errors-phase19-type-assignments May 30, 2025
@zanesq
zanesq deleted the fix/typescript-errors-phase21-possibly-null-undefined branch May 30, 2025 14:58
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.

1 participant