Skip to content

Commit 27baf01

Browse files
committed
Refine types of useModal and show
1 parent 70c1972 commit 27baf01

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/index.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ type NiceModalArgs<T> = T extends keyof JSX.IntrinsicElements | React.JSXElement
221221
: Record<string, unknown>;
222222
export function show<T extends any, C extends any>(
223223
modal: React.FC<C>,
224-
args?: NiceModalArgs<React.FC<C>>,
224+
args?: Partial<NiceModalArgs<React.FC<C>>>,
225225
): Promise<T>;
226226

227227
// export function show<T extends any, C extends React.FC>(modal: C, args?: Omit<React.ComponentProps<C>, 'id'>): Promise<T>;
@@ -293,20 +293,13 @@ const setFlags = (modalId: string, flags: Record<string, unknown>): void => {
293293
};
294294
export function useModal(): NiceModalHandler;
295295
export function useModal(modal: string, args?: Record<string, unknown>): NiceModalHandler;
296-
export function useModal<
297-
T extends React.FC<any>,
298-
ComponentProps extends NiceModalArgs<T>,
299-
PreparedProps extends Partial<ComponentProps> = {} | ComponentProps,
300-
RemainingProps = Omit<ComponentProps, keyof PreparedProps> & Partial<ComponentProps>,
301-
ResolveType = unknown,
302-
>(
303-
modal: T,
304-
args?: PreparedProps,
296+
export function useModal<C extends any, P extends Partial<NiceModalArgs<React.FC<C>>>>(
297+
modal: React.FC<C>,
298+
args?: P,
305299
): Omit<NiceModalHandler, 'show'> & {
306-
show: Partial<RemainingProps> extends RemainingProps
307-
? (args?: RemainingProps) => Promise<ResolveType>
308-
: (args: RemainingProps) => Promise<ResolveType>;
300+
show: (args?: P) => Promise<unknown>;
309301
};
302+
310303
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
311304
export function useModal(modal?: any, args?: any): any {
312305
const modals = useContext(NiceModalContext);

0 commit comments

Comments
 (0)