Skip to content

refactor: eliminate all any types and consolidate type definitions#46

Merged
PatrickSys merged 4 commits intomasterfrom
refactor/eliminate-any-types
Feb 22, 2026
Merged

refactor: eliminate all any types and consolidate type definitions#46
PatrickSys merged 4 commits intomasterfrom
refactor/eliminate-any-types

Conversation

@PatrickSys
Copy link
Owner

Summary

This PR completes a comprehensive refactoring to eliminate unsafe TypeScript typing and consolidate duplicate type definitions:

  • 68 any occurrences eliminated across 15 files — replaced with proper types (unknown, specific interfaces, type guards)
  • Type consolidation: Single source of truth for PatternTrend, PatternCandidateBase, UsageLocation, and GoldenFile
  • No-explicit-any rule promoted to error to prevent regression

Changes

Type Safety

  • Replace Record<string, any> with Record<string, unknown> throughout JSON-parsed data
  • Add type guards and narrowing for external data (JSON parse, AST nodes, decorators, parameters)
  • Use proper ESTree types from @typescript-eslint/typescript-estree for AST node handling
  • Narrow ChunkMetadata index signature from any to unknown

Type Consolidation

  • PatternTrend: Canonical location in types/index.ts, imported by usage-tracker.ts
  • PatternCandidateBase: New shared base for pattern candidates; PatternCandidate extends PatternCandidateBase
  • UsageLocation: Base for both ImportUsage (alias) and SymbolUsage (extends)
  • GoldenFile: Now extends IntelligenceGoldenFile to eliminate file/score duplication

ESLint Enforcement

  • Promote @typescript-eslint/no-explicit-any from warn to error
  • Zero lint errors, 0 any violations

Test Plan

✅ Type check: pnpm type-check — 0 errors
✅ Unit tests: pnpm test — 234/234 passing
✅ Linting: pnpm lint — 0 errors (33 pre-existing console.log warnings in tests)

Fixes: Eliminates technical debt from initial any usage, prevents future unsafe typing.

- Remove 68 `any` occurrences across 15 files with proper TypeScript types
- Replace `Record<string, any>` with `Record<string, unknown>` for JSON
- Add type guards and narrowing for unsafe external data
- Promote @typescript-eslint/no-explicit-any from warn to error
- Consolidate duplicate types: PatternTrend, PatternCandidateBase, UsageLocation
- Make GoldenFile extend IntelligenceGoldenFile to eliminate field duplication
- Define PatternCandidateBase for shared pattern candidate fields
- Create UsageLocation base for ImportUsage and SymbolUsage
- All 234 tests passing, type-check clean, 0 lint errors
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@greptile-apps
Copy link

greptile-apps bot commented Feb 22, 2026

Greptile Summary

Comprehensive elimination of any types across 20 files, replacing them with proper TypeScript types (unknown, specific interfaces, type guards). Consolidates duplicate type definitions (PatternTrend, PatternCandidateBase, UsageLocation, GoldenFile) into src/types/index.ts as a single source of truth. Promotes @typescript-eslint/no-explicit-any from warn to error to prevent regression.

  • Type safety improvements: Record<string, any>Record<string, unknown> throughout; proper TSESTree types for AST node handling in both Angular and generic analyzers; typed interfaces for LanceDB records, cross-encoder model/tokenizer, OpenAI API responses, and HuggingFace pipeline
  • Type consolidation: New shared types (PatternCandidateBase, PatternEntry, PatternsData, IntelligenceData, IntelligenceGoldenFile) create a typed contract for intelligence.json data consumed across the codebase
  • Null safety: Added proper null checks before using cached model/tokenizer in reranker, pipeline in transformers embeddings, and db connection in LanceDB
  • One issue: patternFlags as GoldenFile['patterns'] in src/core/indexer.ts:585 is a type-unsafe cast — the runtime Record<string, boolean> keys (e.g. "dependencyInjection:inject") don't match the declared fixed-field shape. This pre-existed as as any but the new cast gives false confidence in the type

Confidence Score: 4/5

  • This PR is safe to merge — all changes are type-level refactoring with zero behavioral changes, backed by passing type-check, lint, and 234/234 tests.
  • Score of 4 reflects that this is a pure type-safety refactoring with no runtime behavior changes, full test coverage, and zero lint errors. Deducted 1 point for the GoldenFile patterns type mismatch which is a pre-existing issue that this PR perpetuates rather than fixes — it replaces as any with an equally unsound but more specific as GoldenFile['patterns'] cast.
  • src/core/indexer.ts — contains the unsound GoldenFile['patterns'] cast at line 585. src/analyzers/angular/index.ts — largest file change with several inline as casts for AST node shapes.

Important Files Changed

Filename Overview
src/types/index.ts Core type consolidation: adds UsageLocation, PatternTrend, PatternCandidateBase, PatternCandidate, PatternEntry, PatternsData, IntelligenceGoldenFile, IntelligenceData. Replaces all Record<string, any> with Record<string, unknown>. Well-structured type hierarchy.
src/analyzers/angular/index.ts Major refactoring from any to proper TSESTree types for AST node handling. Adds AngularInput/AngularOutput interfaces. Some inline as casts for callee shapes are pragmatic but slightly loose. Overall significant improvement in type safety.
src/core/indexer.ts Replaces any with IntelligenceData, Dependency, ArchitecturalLayer. Contains a type-unsafe as GoldenFile['patterns'] cast at line 585 — dynamic Record<string, boolean> keys don't match the fixed GoldenFile.patterns shape.
src/core/reranker.ts Replaces module-level any with CrossEncoderTokenizer and CrossEncoderModel interfaces. Adds proper null check before using cached model/tokenizer. Clean improvement.
src/embeddings/transformers.ts Replaces any pipeline with FeatureExtractionPipelineType. Adds proper null checks before pipeline usage. Pipeline cast is well-documented with TS2590 justification.
src/storage/lancedb.ts Replaces any with proper LanceDB Connection/Table types and LanceDBRecord interface. Adds null checks for db before operations. Well-structured refactoring.
src/tools/search-codebase.ts Largest file change. Moves DecisionCard to types.ts, uses IntelligenceData/PatternsData throughout. Adds RelationshipsData interface. Properly types args destructuring. Uses ChunkMetadata for scope helpers.
src/utils/usage-tracker.ts Consolidates PatternTrend (re-exports from types/index.ts), uses PatternCandidateBase, IntelligenceGoldenFile, UsageLocation. ImportUsage is now a type alias. GoldenFile extends IntelligenceGoldenFile.
eslint.config.js Promotes no-explicit-any from warn to error. Prevents regression.

Class Diagram

%%{init: {'theme': 'neutral'}}%%
classDiagram
    class UsageLocation {
        +string file
        +number line
    }
    class PatternCandidateBase {
        +string name
        +string frequency
        +PatternTrend trend
        +string guidance
        +string newestFileDate
    }
    class PatternCandidate {
        +object canonicalExample
        +number count
    }
    class PatternEntry {
        +PatternCandidate primary
        +PatternCandidate[] alsoDetected
    }
    class IntelligenceGoldenFile {
        +string file
        +number score
    }
    class GoldenFile {
        +object patterns
    }
    class IntelligenceData {
        +PatternsData patterns
        +IntelligenceGoldenFile[] goldenFiles
        +object internalFileGraph
        +string generatedAt
    }
    class ImportUsage {
        <<type alias>>
    }
    class SymbolUsage {
        +string preview
    }
    class RuntimePatternPrimary {
        +number count
        +string[] examples
    }

    PatternCandidateBase <|-- PatternCandidate : extends
    PatternCandidateBase <|-- RuntimePatternPrimary : extends
    IntelligenceGoldenFile <|-- GoldenFile : extends
    UsageLocation <|-- SymbolUsage : extends
    UsageLocation <.. ImportUsage : alias
    PatternEntry o-- PatternCandidate : primary / alsoDetected
    IntelligenceData o-- PatternEntry : patterns map
    IntelligenceData o-- IntelligenceGoldenFile : goldenFiles
Loading

Last reviewed commit: 1b507bf

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

…tor signal input/output handling

- Introduced IndexChunk interface for better type definition of chunk properties.
- Refactored signal input() and output() handling to improve clarity and type safety.
- Simplified logic for determining required properties in signal-based inputs and outputs.
- Updated type assertions to leverage the new IndexChunk interface for chunk processing.
@PatrickSys PatrickSys merged commit 7c4e684 into master Feb 22, 2026
3 checks passed
@PatrickSys PatrickSys deleted the refactor/eliminate-any-types branch February 22, 2026 19:45
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