eBay / nice-modal-react

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

feat: optimize useModal ts type #144

Closed IVLIU closed 4 weeks ago

IVLIU commented 4 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 4 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.