theKashey / react-focus-on

🎯 Solution for WAI ARIA compatible modal dialogs or full-screen tasks, you were looking for
MIT License
333 stars 14 forks source link

Add support of exactOptionalPropertyTypes compiler flag #55

Closed Dremora closed 2 years ago

Dremora commented 2 years ago

I'm using this library in a project with exactOptionalPropertyTypes enabled.

Unfortunately, currently I can't conditionally pass undefined into optional properties. For example, this code doesn't work:

<FocusOn onClickOutside={closeOnOutsideClick ? onClose : undefined}>

This is because with the new flag, TypeScript treats missing properties and undefined as semantically distinct, and this library only allows for properties to be missing (but not to be set to undefined).

Read more about the compiler flag in TypeScript 4.4 blog post. The intention is to migrate all type definitions to support this flag:

We’ll be making updates to DefinitelyTyped and other definitions to try to make the transition as straightforward as possible

theKashey commented 2 years ago

A very good move from TS. But with a very wide impact as well. There should be some way to keep pieces of the code which is ok with the old behavior intact WithUndefinedOptions<OldType>, but I've failed to create such generic.

theKashey commented 2 years ago

Accepting and merging, but the release will be delayed for a few days until other moving pieces of this package will complete current iteration.