app icon indicating copy to clipboard operation
app copied to clipboard

Replace string array with enum for PreferencePaneId and add generic type to Dropdown component

Open besdar opened this issue 10 months ago • 2 comments
trafficstars

This pull request makes two improvements to the codebase:

  1. Replaces the existing string array PREFERENCE_PANE_IDS with an enum PreferencePaneId to improve type safety and maintainability.

  2. Adds a generic type T to the Dropdown component to improve type safety and flexibility.

besdar avatar Jan 17 '25 17:01 besdar

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 avatar Mar 09 '25 07:03 amanharwara

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.

besdar avatar Mar 27 '25 08:03 besdar