eBay / nice-modal-react

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

feat: optimize useModal ts type #144

Closed IVLIU closed 5 months ago

IVLIU commented 9 months ago

I added a generic parameter to useModal and NiceModalHandler, which will affect the type of resolve and the return value type of show.

const { resolve,  show } = useModal<string, number>('id')
/** good */
resolve(10)
/** bad */
resolve('10')

show('test').then((value) => {
/** value is a number type */
})
supnate commented 8 months ago

Thanks @IVLIU for the PR!

However, there have been several attempts to enhance types of APIs like useModal, modal.show, etc, but all failed and rolled back.

So I need to carefully look into code. You can also revisit the code again to make sure it covers all possibilities and is backward compatible with the current type definition.