Closed dwelle closed 3 years ago
Note that a slightly simpler but still working option could've been to only add the = false
part:
export function fileOpen<M extends boolean = false>(options?: {
/** Acceptable MIME types. [] */
mimeTypes?: string[];
/** Acceptable file extensions. Defaults to "". */
extensions?: string[];
/** Suggested file description. Defaults to "". */
description?: string;
/** Allow multiple files to be selected. Defaults to false. */
multiple?: M;
}): M extends true ? Promise<File> : Promise<File[]>;
👍 Happy to merge a quick PR.
Note that a slightly simpler but still working option could've been to only add the = false part:
That won't work when you explicitly specify multiple: undefined
. An edge case, but correct.
This fixes the return type of
fileOpen
whenoptions.multiple
isundefined
(false
by default).