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

Improve typing of show function #102

Closed fpmanuel closed 1 year ago

fpmanuel commented 1 year ago

The show function doesn't infer the types of the modal you are passing as first parameter. By passing a generic we can do so :surfer:

codecov-commenter commented 1 year ago

Codecov Report

Merging #102 (7a36e2d) into main (f146959) will not change coverage. The diff coverage is n/a.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff            @@
##              main      #102   +/-   ##
=========================================
  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.

chen86860 commented 1 year ago

what's the time of publish this typing fix? I need this typing safe function in urgently.

supnate commented 1 year ago

Published in v1.2.9.

francislavoie commented 1 year ago

This seems like a regression to me. My modal doesn't work with this.

TS2769: No overload matches this call.
   Overload 1 of 3, '(modal: FC<Props & NiceModalHocProps>, args?: Omit<Props & NiceModalHocProps, "id"> | undefined): Promise<...>', gave the following error. 
    Argument of type '{ title: string; content: () => JSX.Element; cancelLabel: string; }' is not assignable to parameter of type 'Omit<Props & NiceModalHocProps, "id">'.
       Object literal may only specify known properties, and 'cancelLabel' does not exist in type 'Omit<Props & NiceModalHocProps, "id">'.
   Overload 2 of 3, '(modal: string, args?: Record<string, unknown> | undefined): Promise<unknown>', gave the following error.
     Argument of type 'FC<Props & NiceModalHocProps>' is not assignable to parameter of type 'string'.
   Overload 3 of 3, '(modal: string, args: { title: string; content: () => Element; cancelLabel: string; }): Promise<unknown>', gave the following error.
     Argument of type 'FC<Props & NiceModalHocProps>' is not assignable to parameter of type 'string'.

I'm trying to pass in a modal I created with NiceModal.create() and it breaks with this change.

I'm gonna have to pin to 1.2.8 for the time being.

supnate commented 1 year ago

@fperaltalitebox would you plz take a look?

adrhumphreys commented 1 year ago

I've also had to pin to 1.2.8 to resolve this