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

feat: optimize useModal ts type #144

Closed IVLIU closed 6 months ago

IVLIU commented 10 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 9 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.