-
Notifications
You must be signed in to change notification settings - Fork 13
refactor(typescript): prevent any #5470
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
base: main
Are you sure you want to change the base?
Conversation
|
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 aims to reduce the use of any types in TypeScript by replacing them with more specific types. The change updates the handleKeyboardPress function signature in the custom-select component to use GeneralKeyboardEvent<HTMLInputElement> instead of any.
Key Changes
- Imported
GeneralKeyboardEventtype from shared model - Updated
handleKeyboardPresstype signature fromanytoGeneralKeyboardEvent<HTMLInputElement>in both model definition and implementation
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/components/src/components/custom-select/model.ts | Added GeneralKeyboardEvent import and updated handleKeyboardPress type in DBCustomSelectDefaultState |
| packages/components/src/components/custom-select/custom-select.lite.tsx | Added GeneralKeyboardEvent import and updated handleKeyboardPress parameter type in implementation |
Comments suppressed due to low confidence (2)
packages/components/src/components/custom-select/model.ts:288
- The
handleDropdownToggleparameter type should be updated fromanyto match its implementation, which usesGeneralEvent<HTMLDetailsElement>. The implementation at line 176 of custom-select.lite.tsx already has the correct type.
handleDropdownToggle: (event: any) => void;
packages/components/src/components/custom-select/model.ts:287
- The
handleSelectAllandhandleClearAllparameter types should be updated fromanytoClickEvent<HTMLButtonElement>or a more specific event type. Both implementations callevent.stopPropagation(), indicating they receive standard DOM events. Review the actual event sources to determine the most appropriate type.
handleSelectAll: (event: any) => void;
handleClearAll: (event: any) => void;
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
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (4)
packages/components/src/components/custom-select/custom-select.lite.tsx:288
- The
handleArrowDownUpmethod still usesanyfor the event parameter. According to the model.ts changes (line 295), this should be typed asGeneralKeyboardEvent<HTMLElement>to match the interface definition and align with the PR's goal of removinganytypes.
handleArrowDownUp: (event: any) => {
packages/components/src/components/custom-select/custom-select.lite.tsx:463
- The
handleDocumentCloseimplementation still usesanyfor the event parameter. According to the model.ts changes (line 289), this should be typed asGeneralEvent<HTMLElement>to match the interface definition.
handleDocumentClose: (event: any) => {
packages/components/src/components/custom-select/custom-select.lite.tsx:529
- The
handleSelectAllmethod still usesanyfor the event parameter. Based on usage at line 1062 where it's called from anonChangehandler on a checkbox input, this should be typed asChangeEvent<HTMLInputElement>to provide proper type safety.
handleSelectAll: (event: any) => {
packages/components/src/components/custom-select/custom-select.lite.tsx:636
- The
handleClearAllmethod still usesanyfor the event parameter. Based on usage at line 1179 where it's called from anonClickhandler on a DBButton, this should be typed asClickEvent<HTMLButtonElement>to provide proper type safety.
handleClearAll: (event: any) => {
Co-authored-by: Copilot <[email protected]>
Proposed changes
In general we're using
anyway too often, whereas it should only be used in rare cases if at all (in some it might still beunknown).Types of changes
Further comments
🔭🐙🐈 Test this branch here: https://design-system.deutschebahn.com/core-web/review/refactor-typescript-migrate-any