Replace string array with enum for PreferencePaneId and add generic type to Dropdown component#2890
Open
besdar wants to merge 1 commit intostandardnotes:mainfrom
Open
Replace string array with enum for PreferencePaneId and add generic type to Dropdown component#2890besdar wants to merge 1 commit intostandardnotes:mainfrom
besdar wants to merge 1 commit intostandardnotes:mainfrom
Conversation
571bc4f to
3951a31
Compare
3951a31 to
c7b3ddc
Compare
Member
|
Hi, the dropdown changes seem ok, but could you give an example in the codebase where the string array for the ids is less type-safe and maintainable? |
Author
@amanharwara, here’s an example: - onChange={(paneId) => {
- selectPane(paneId as PreferencePaneId)
- }}
+ onChange={selectPane}In this case, the type assertion "as" is no longer needed, which enhances type safety. Another example is here: - menuItems.push({ id: 'home-server', label: 'Home Server', icon: 'server', order: 5 })
+ menuItems.push({ id: PreferencePaneId.HomeServer, label: 'Home Server', icon: 'server', order: 5 })Using an enum title provides more context in the code, as it represents a specific preference pane ID rather than just a generic string. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request makes two improvements to the codebase:
Replaces the existing string array
PREFERENCE_PANE_IDSwith an enumPreferencePaneIdto improve type safety and maintainability.Adds a generic type
Tto theDropdowncomponent to improve type safety and flexibility.