nice-modal-react
nice-modal-react copied to clipboard
Can the .show() method be smarter about its return type?
https://github.com/eBay/nice-modal-react/blob/979c283892c4f16a4a2d5ecf582d1500eca3807a/src/index.tsx#L216
Right now, the .show()
method always returns Promise<unknown>
. If I'm not mistaken, whatever I end up passing into .resolve()
is what gets returned to .show()
.
I'm only still learning TypeScript, but can't you use generics to accept a type? Right now, I'm having to do a manual type-check method in order to assert my return type. It feels like I shouldn't have to do that.
For example, if when constructing the modal, you do
modal.resolve(true)
In the app when you do
modal.show().then((res) => whatever...
TypeScript thinks res
is unknown
. Surely there's a way I can assert that it's a boolean?