GoogleChromeLabs / browser-fs-access

File System Access API with legacy fallback in the browser
https://googlechromelabs.github.io/browser-fs-access/demo/
Apache License 2.0
1.38k stars 84 forks source link

ensure conditional type works with default value #21

Closed dwelle closed 3 years ago

dwelle commented 3 years ago

This fixes the return type of fileOpen when options.multiple is undefined (false by default).

RReverser commented 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[]>;
tomayac commented 3 years ago

👍 Happy to merge a quick PR.

dwelle commented 3 years ago

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.