type: add OpenDialogReturn generic type (#919)

* type: add OpenDialogReturn generic type

* chore: run pnpm format

* type: export OpenDialogReturn type

* chore: run pnpm format
pull/923/head
Shubham Parihar 1 year ago committed by GitHub
parent 8dea78ac7d
commit 18cb861b52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -98,18 +98,14 @@ interface ConfirmDialogOptions {
cancelLabel?: string; cancelLabel?: string;
} }
async function open( type OpenDialogReturn<T extends OpenDialogOptions> = T["directory"] extends true
options?: OpenDialogOptions & { multiple?: false; directory?: false }, ? T["multiple"] extends true
): Promise<null | FileResponse>; ? string[] | null
async function open( : string | null
options?: OpenDialogOptions & { multiple?: true; directory?: false }, : T["multiple"] extends true
): Promise<null | FileResponse[]>; ? FileResponse[] | null
async function open( : FileResponse | null;
options?: OpenDialogOptions & { multiple?: false; directory?: true },
): Promise<null | string>;
async function open(
options?: OpenDialogOptions & { multiple?: true; directory?: true },
): Promise<null | string[]>;
/** /**
* Open a file/directory selection dialog. * Open a file/directory selection dialog.
* *
@ -162,9 +158,9 @@ async function open(
* *
* @since 2.0.0 * @since 2.0.0
*/ */
async function open( async function open<T extends OpenDialogOptions>(
options: OpenDialogOptions = {}, options: T = {} as T,
): Promise<null | string | string[] | FileResponse | FileResponse[]> { ): Promise<OpenDialogReturn<T>> {
if (typeof options === "object") { if (typeof options === "object") {
Object.freeze(options); Object.freeze(options);
} }
@ -298,6 +294,7 @@ export type {
DialogFilter, DialogFilter,
FileResponse, FileResponse,
OpenDialogOptions, OpenDialogOptions,
OpenDialogReturn,
SaveDialogOptions, SaveDialogOptions,
MessageDialogOptions, MessageDialogOptions,
ConfirmDialogOptions, ConfirmDialogOptions,

Loading…
Cancel
Save