eBay / nice-modal-react

A modal state manager for React.
https://ebay.github.io/nice-modal-react
MIT License
2.1k stars 122 forks source link

Make component and props' types optional in the standalone show function #151

Open damianstasik opened 8 months ago

damianstasik commented 8 months ago

This PR simplifies specifying type of the resolved value from the show function. Currently, if you want to provide a precise type of the value resolved from a promise, you'll need to provide 1/2 additional types – depending on whether you use an ID or a modal reference.

Before:

NiceModal.show<TypeOfTheValue, ComponentType, PropsType>(SomeModal, someProps).then((value) => { ... });

Both ComponentType and PropsType can be automatically inferred by TS, so having to type them all each time you want to provide TypeOfTheValue is a bit inconvenient.

After:

NiceModal.show<TypeOfTheValue>(SomeModal, someProps).then((value) => { ... });

Now you can provide just the first type while the rest gets inferred. Let me know what you think.