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

Better support for using with exactOptionalPropertyTypes enabled #2818

Open
hornta opened this issue Mar 15, 2024 · 2 comments
Open

Better support for using with exactOptionalPropertyTypes enabled #2818

hornta opened this issue Mar 15, 2024 · 2 comments

Comments

@hornta
Copy link

hornta commented Mar 15, 2024

We recently enabled exactOptionalPropertyTypes for our code base because we had a bug that could have been prevented if that flag was enabled in our tsconfig.json. We've fixed some of the issues caused by enabling this flag now and now we found it caused a problem with when we pass undefined as a property to <FloatingFocusManager>.

We have this code in our codebase and this is a issue because the type for initialFocus is doesn't contain an explicit undefined.

<FloatingFocusManager
  context={floatingContext}
  initialFocus={
    typeof children === "function" ? initialElementRef : undefined
  }
>

We can get around this problem by moving some code around like below but it's not pretty.

const inner = ...

if(typeof children === "function") {
  return <FloatingFocusManager context={floatingContext} initialFocus={initialElementRef}>{inner}</FloatingFocusManager>
} else {
  return <FloatingFocusManager context={floatingContext}>{inner}</FloatingFocusManager>
}

I can provide a PR to make it easier for code bases using exactOptionalPropertyTypes to use floating-ui.

@hornta hornta changed the title Support for using with exactOptionalPropertyTypes enabled Better support for using with exactOptionalPropertyTypes enabled Mar 15, 2024
@atomiks
Copy link
Collaborator

atomiks commented Apr 6, 2024

So this only involves adding | undefined to the types instead of relying on ?: alone?

@hornta
Copy link
Author

hornta commented Apr 7, 2024

More or less, yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants