TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

support type narrowing for FileSystemHandle

Open SimonSiefke opened this issue 3 years ago • 1 comments

Type narrowing for FileSystemHandles would make working with file system handles much easier

const fileHandle: FileSystemHandle = getFileHandle();

if (fileHandle.kind === "file") {
  // infer that fileHandle is a FileSystemFileHandle
} else if (fileHandle.kind === "directory") {
  // infer that fileHandle is a FileSystemDirectoryHandle
}

SimonSiefke avatar Feb 03 '23 10:02 SimonSiefke

We need a new name for the enum since FileSystemHandle is already the name of the superclass. PR welcome if someone has a good candidate.

Any function returning FileSystemHandle should return that enum instead.

saschanaz avatar Feb 05 '23 09:02 saschanaz