Skip to content
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

🏷️ Make Autocomplete options prop readonly #3487

Closed

Conversation

magnh
Copy link
Contributor

@magnh magnh commented Jun 5, 2024

What does this pull request change?

Allow options prop in Autocomplete to be readonly. This way you can pass readonly arrays such as the one below without getting any TypeScript errors.

const READONLY_OPTIONS = [
  { id: 1, label: "One" },
  { id: 2, label: "Two" },
] as const

Why is this pull request needed?

The autocomplete should not change the options array anyways, so I cannot see any reason why not to support readonly options prop.

(became a fork by accident)

@magnh magnh self-assigned this Jun 5, 2024
@magnh magnh force-pushed the chore/make-autocomplete-options-readonly branch from dfb3e4f to a046663 Compare June 5, 2024 06:37
@@ -250,7 +250,7 @@ export type AutocompleteChanges<T> = { selectedItems: T[] }

export type AutocompleteProps<T> = {
/** List of options in dropdown */
options: T[]
options: readonly T[]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this needs some more work for typescript to be happy
bilde

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix this (adding readonly) in another pr for #3514. By the way looks like downshift is happy again if I add as T[] behind availableItems

@oddvernes
Copy link
Collaborator

Will be resolved by #3515 instead

@oddvernes oddvernes closed this Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants