@@ -209,12 +209,11 @@ 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
- ? Omit < React . ComponentProps < T > , 'id' >
212
+ ? Partial < 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 > ;
218
217
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
219
218
export function show ( modal : React . FC < any > | string , args ?: NiceModalArgs < React . FC < any > > | Record < string , unknown > ) {
220
219
const modalId = getModalId ( modal ) ;
@@ -276,20 +275,11 @@ const setFlags = (modalId: string, flags: Record<string, unknown>): void => {
276
275
dispatch ( setModalFlags ( modalId , flags ) ) ;
277
276
} ;
278
277
export function useModal ( ) : NiceModalHandler ;
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
- > (
278
+ export function useModal < T extends string > ( modal : T , args ?: Record < string , unknown > ) : NiceModalHandler ;
279
+ export function useModal < T extends React . FC < any > > (
286
280
modal : 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
- } ;
281
+ args ?: NiceModalArgs < T > ,
282
+ ) : NiceModalHandler < NiceModalArgs < T > > ;
293
283
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
294
284
export function useModal ( modal ?: any , args ?: any ) : any {
295
285
const modals = useContext ( NiceModalContext ) ;
@@ -399,7 +389,7 @@ export const create = <P extends {}>(Comp: React.ComponentType<P>): React.FC<P &
399
389
} ;
400
390
401
391
// All registered modals will be rendered in modal placeholder
402
- export const register = < T extends React . FC < any > > ( id : string , comp : T , props ?: Partial < NiceModalArgs < T > > ) : void => {
392
+ export const register = < T extends React . FC < any > > ( id : string , comp : T , props ?: NiceModalArgs < T > ) : void => {
403
393
if ( ! MODAL_REGISTRY [ id ] ) {
404
394
MODAL_REGISTRY [ id ] = { comp, props } ;
405
395
} else {
0 commit comments