app
app copied to clipboard
Replace string array with enum for PreferencePaneId and add generic type to Dropdown component
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.
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?
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?
@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.