eBay / nice-modal-react

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

Fix `useModal` default value type #83

Closed alexandredev3 closed 1 year ago

alexandredev3 commented 1 year ago

This PR fixes the default value of the PreparedProps generic type.

The PreparedProps generic needs an object as a default value. Without the default value object, Typescript would set all the modal.show() props to optional even if they're not unless the user initially passes an object to the useModal(). image

But if the PreparedProps generic has an object as a default value. Typescript couldn't possibly know the initial props that the useModal receives because the default value of the PreparedProps generic was just an object. image

My solution was to set the PreparedProps generic default value to {} | ComponentProps. That way, Typescript knows what props the modal receives and if they are required or optional. image

codecov-commenter commented 1 year ago

Codecov Report

Merging #83 (fe80b2f) into main (45b33c0) will not change coverage. The diff coverage is n/a.

@@            Coverage Diff            @@
##              main       #83   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          201       201           
  Branches        30        30           
=========================================
  Hits           201       201           
Impacted Files Coverage Δ
src/index.tsx 100.00% <ø> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

supnate commented 1 year ago

Thanks @alexandredev3 for the quick fix!