@@ -209,11 +209,12 @@ const getModalId = (modal: string | React.FC<any>): string => {
209
209
210
210
/** omit id and partial all required props */
211
211
type NiceModalArgs < T > = T extends keyof JSX . IntrinsicElements | React . JSXElementConstructor < any >
212
- ? Partial < Omit < React . ComponentProps < T > , 'id' > >
212
+ ? Omit < React . ComponentProps < T > , 'id' >
213
213
: Record < string , unknown > ;
214
214
215
215
export function show < T extends any , C extends React . FC > ( modal : C , args ?: Omit < React . ComponentProps < C > , 'id' > ) : Promise < T > ;
216
216
export function show < T extends any > ( modal : string , args ?: Record < string , unknown > ) : Promise < T > ;
217
+ export function show < T extends any , P extends any > ( modal : string , args : P ) : Promise < T > ;
217
218
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
218
219
export function show ( modal : React . FC < any > | string , args ?: NiceModalArgs < React . FC < any > > | Record < string , unknown > ) {
219
220
const modalId = getModalId ( modal ) ;
@@ -275,11 +276,20 @@ const setFlags = (modalId: string, flags: Record<string, unknown>): void => {
275
276
dispatch ( setModalFlags ( modalId , flags ) ) ;
276
277
} ;
277
278
export function useModal ( ) : NiceModalHandler ;
278
- export function useModal < T extends string > ( modal : T , args ?: Record < string , unknown > ) : NiceModalHandler ;
279
- export function useModal < T extends React . FC < any > > (
279
+ export function useModal ( modal : string , args ?: Record < string , unknown > ) : NiceModalHandler ;
280
+ export function useModal <
281
+ T extends React . FC < any > ,
282
+ ComponentProps extends NiceModalArgs < T > ,
283
+ PreparedProps extends Partial < ComponentProps > = { } ,
284
+ RemainingProps = Omit < ComponentProps , keyof PreparedProps > & Partial < ComponentProps >
285
+ > (
280
286
modal : T ,
281
- args ?: NiceModalArgs < T > ,
282
- ) : NiceModalHandler < NiceModalArgs < T > > ;
287
+ args ?: PreparedProps
288
+ ) : Omit < NiceModalHandler , 'show' > & {
289
+ show : { [ K in keyof RemainingProps ] : RemainingProps [ K ] extends Exclude < RemainingProps [ keyof RemainingProps ] , undefined > ? K : never } [ keyof RemainingProps ] extends undefined
290
+ ? ( args ?: RemainingProps ) => Promise < unknown >
291
+ : ( args : RemainingProps ) => Promise < unknown >
292
+ } ;
283
293
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
284
294
export function useModal ( modal ?: any , args ?: any ) : any {
285
295
const modals = useContext ( NiceModalContext ) ;
@@ -389,7 +399,7 @@ export const create = <P extends {}>(Comp: React.ComponentType<P>): React.FC<P &
389
399
} ;
390
400
391
401
// All registered modals will be rendered in modal placeholder
392
- export const register = < T extends React . FC < any > > ( id : string , comp : T , props ?: NiceModalArgs < T > ) : void => {
402
+ export const register = < T extends React . FC < any > > ( id : string , comp : T , props ?: Partial < NiceModalArgs < T > > ) : void => {
393
403
if ( ! MODAL_REGISTRY [ id ] ) {
394
404
MODAL_REGISTRY [ id ] = { comp, props } ;
395
405
} else {
0 commit comments