-
Notifications
You must be signed in to change notification settings - Fork 9
refactor(types): eliminate explicit any types across Dify services #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Replace Record<string, any> with Record<string, unknown> for better type safety - Replace any[] with proper typed arrays (DifyRetrieverResource[], DifyMessageFile[]) - Standardize error types to use Error instead of any - Add type-safe data extraction with runtime validation - Simplify interface inheritance using type aliases - Fix ESLint require() imports by converting to ES6 imports - Remove unused imports and variables to satisfy linting rules - Maintain backward compatibility through proper type assertions - Keep necessary any type in DifyApiError for API compatibility Affected files: - lib/services/dify/types.ts: Core type definitions with Record<string, unknown> - lib/services/dify/chat-service.ts: Chat streaming with proper event types - lib/services/dify/completion-service.ts: Completion service error handling - lib/hooks/use-chat-interface.ts: File handling with ChatUploadFile type assertions - lib/hooks/use-create-conversation.ts: Store imports optimization All TypeScript validation and linting passes, improving code maintainability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR eliminates explicit any types across Dify services to improve type safety and resolve linting errors. The refactoring replaces unsafe type usage with proper TypeScript types while maintaining full API compatibility.
- Replaced
Record<string, any>withRecord<string, unknown>for better type safety - Converted
any[]to properly typed arrays (DifyRetrieverResource[],DifyMessageFile[]) - Enhanced error handling with proper
Errortypes instead ofany
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/services/dify/types.ts | Core type definitions updated to use Record<string, unknown> and proper array types |
| lib/services/dify/completion-service.ts | Enhanced error handling with proper Error type conversion |
| lib/services/dify/chat-service.ts | Improved streaming with type-safe event handling and data extraction |
| lib/hooks/use-create-conversation.ts | Added proper type imports and removed dynamic require() calls |
| lib/hooks/use-chat-interface.ts | Type-safe file handling with proper ChatUploadFile assertions |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
What & Why
What: Comprehensive refactoring to eliminate explicit
anytypes across Dify services and improve type safetyWhy: Resolves linting errors and enhances code maintainability by replacing unsafe type usage with proper TypeScript types
Fixes #193
Pre-PR Checklist
Run these:
pnpm type-checkpnpm format:checkpnpm lint(Dify services now clean, other pre-existing issues remain)pnpm buildpnpm i18n:check(not applicable)Type
Key Changes
Type Safety Improvements
Record<string, any>withRecord<string, unknown>for better type safetyany[]to properly typed arrays (DifyRetrieverResource[],DifyMessageFile[])Errorinstead ofanywhere possibleService Layer Improvements
ChatUploadFiletype assertionsMaintained Compatibility
anytype for API compatibility with external Dify servicesTechnical Details
This refactoring significantly improves code maintainability and type safety while preserving all existing functionality. The focused approach on Dify services creates a foundation for similar improvements across the codebase.