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

Types: Accept async functions for event handler options? #1616

Open
karlhorky opened this issue Jul 20, 2024 · 0 comments
Open

Types: Accept async functions for event handler options? #1616

karlhorky opened this issue Jul 20, 2024 · 0 comments

Comments

@karlhorky
Copy link

  • downshift version: 9.0.6
  • node version: 20.15.0
  • npm version: 10.7.0

Relevant code or config

  const {
    // ...
  } = useCombobox({
    // ...
    onInputValueChange: async ({ inputValue: changedInputValue }) => {
      const response = await fetchApi(
        `/search-results?q=${changedInputValue}`,
        {
          method: 'GET',
        },
      );

      if ('errors' in response) {
        return;
      }

      setResults(response.results);
    },
  });

What you did:

Use async function in option for hook (in my case, useCombobox)

What happened:

The @typescript-eslint/no-misused-promises ESLint rule shows a misused promise:

Promise-returning function provided to property where a void return was expected. eslint (@typescript-eslint/no-misused-promises)

Screenshot 2024-07-20 at 18 37 14

Reproduction repository:

--

Problem description:

The types for useCombobox don't allow for async functions with event handler options:

onSelectedItemChange?: (changes: UseComboboxSelectedItemChange<Item>) => void
onIsOpenChange?: (changes: UseComboboxIsOpenChange<Item>) => void
onHighlightedIndexChange?: (
changes: UseComboboxHighlightedIndexChange<Item>,
) => void
onStateChange?: (changes: UseComboboxStateChange<Item>) => void
onInputValueChange?: (changes: UseComboboxInputValueChange<Item>) => void

Suggested solution:

Change the return type of the event handler function types from void to void | Promise<void>

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

No branches or pull requests

1 participant