refactor: replace any types with proper TypeScript types for strict type safety#648
Conversation
…safety Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
any types with proper TypeScript types for strict type safety
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
1 similar comment
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Pull Request Overview
This PR successfully eliminates all any type usage in production code (3 instances) by replacing them with proper TypeScript types, specifically using Record<string, unknown> and index signatures with unknown type. This aligns with the TypeScript React Agent guidelines requiring strict type safety and avoiding any types.
Key changes:
- Replaced
as anytype assertions withRecord<string, unknown>in type guard functions for safer type narrowing - Changed index signature from
[key: string]: anyto[key: string]: unknowninTechnicalImplementationDetailsinterface - Added explicit optional properties
expertiseLevelanddevelopmentEffortto clarify interface expectations
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/utils/typeGuards.ts | Replaced two instances of as any assertions with Record<string, unknown> in type guard functions isSecurityLevelWidgetProps and isCIAImpactSummaryWidgetProps, improving type safety while maintaining runtime property checking functionality |
| src/types/cia-services.ts | Replaced [key: string]: any with [key: string]: unknown in TechnicalImplementationDetails interface and added explicit optional properties expertiseLevel and developmentEffort for better type documentation and extensibility |
| expertiseLevel?: string; // Expertise level required | ||
| developmentEffort?: string; // Development effort estimate |
There was a problem hiding this comment.
The new properties expertiseLevel and developmentEffort may cause confusion as they seem to duplicate information already present in the effort object (effort.expertise and effort.development).
Consider:
- Documenting the distinction between these properties with JSDoc comments
- Or, if they serve the same purpose, consider using the existing
effortobject properties consistently throughout the codebase
Currently, SecurityResourcesWidget accesses these new properties (lines 522, 527, 548, 553, 574, 579), but the actual service implementation (TechnicalImplementationService.getTechnicalImplementation) doesn't return them - only test mocks do. This suggests either:
- Future implementation is planned
- The widget should be using
effort.expertiseandeffort.developmentinstead
| expertiseLevel?: string; // Expertise level required | |
| developmentEffort?: string; // Development effort estimate |
|
@copilot apply changes based on the comments in this thread |
Pull Request Description
Eliminates all
anytype usage in production code (3 instances) to enforce strict type safety per TypeScript React Agent guidelines and ISMS policy.Changes:
TechnicalImplementationDetailsinterface: Replaced[key: string]: anywith[key: string]: unknownand added missing explicit propertiesexpertiseLevel?: stringanddevelopmentEffort?: stringthat were accessed inSecurityResourcesWidgetas anyassertions withRecord<string, unknown>inisSecurityLevelWidgetPropsandisCIAImpactSummaryWidgetPropsResult: Zero
anytypes in src/ (excluding tests), improved compile-time safety, better IDE support.Type of Change
Component(s) Modified
CIA Impact Area
Security Level Impact
Test Coverage Impact
Testing Performed
Screenshots/Examples
N/A - Type system changes only, no runtime behavior modification.
Related Issues
Closes #[issue_number]
Checklist
Additional Notes
All 1545 tests pass. TypeScript strict mode compilation successful. No runtime behavior changes—purely type system improvements.
Original prompt
This section details on the original issue you should resolve
<issue_title>🔒 Replace 'any' types with proper TypeScript types for strict type safety</issue_title>
<issue_description>## 🤖 Recommended Agent: @typescript-react-agent
🎯 Objective
Replace all
anytype usages with proper TypeScript types to achieve strict type safety and eliminate runtime type errors for v1.0 release.📋 Background
The TypeScript React Agent guidelines explicitly state: "ALWAYS use explicit types and interfaces; avoid
any(useunknownif needed)". The codebase currently has 29 instances ofanytype usage (excluding test files), which reduces type safety and increases risk of runtime errors. Per ISMS Secure Development Policy, strict TypeScript configuration is required for code quality.📊 Current State (Measured Metrics)
anytype usages: 29 instances across source files (excluding tests)src/types/cia-services.ts:163-[key: string]: anyin interfaceExample from codebase:
✅ Acceptance Criteria
anytypes in production code (src/ excluding tests)anywith proper types: specific interfaces, union types, orunknownwhere type is genuinely unknown🛠️ Implementation Guidance for @typescript-react-agent
Agent-Specific Instructions:
✅ Check reusable types first in
src/types/before creating new types✅ Use utility types (Pick, Omit, Partial, Record) for type composition
✅ Prefer
unknownoveranywhen type is genuinely unknown✅ Add type guards when narrowing from
unknownto specific types✅ Document decisions with JSDoc for complex type choices
Step 1: Audit All
anyUsageStep 2: Categorize and Replace
Category 1: Index Signatures (High Priority)
Category 2: Function Parameters
Category 3: Event Handlers
Category 4: Generic Data Structures
Step 3: Leverage Existing Types
Reuse from
src/types/:cia.ts- SecurityLevel, CIAComponent typesbusinessImpact.ts- Impact analysis typeswidgets.ts- Widget-specific typescompliance.ts- Compliance framework typescomponentPropExports.ts- Component prop interfacesStep 4: Add Type Guards