Skip to content

Commit

Permalink
Fix TypeScript error about getFile not existing
Browse files Browse the repository at this point in the history
This error was shown because getFile is a method of the more specific
type FileSystemFileHandle, not the base FileSystemHandle:

    src/app.js:844:29 - error TS2339: Property 'getFile' does not exist on type 'FileSystemHandle'.

    844         file = await handle.getFile();
                                    ~~~~~~~

    Found 1 error in src/app.js:844

Use instanceof for type narrowing.

Back down to zero errors!
  • Loading branch information
1j01 committed May 21, 2024
1 parent 894d68e commit 9870bb2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
"webglcontextlost",
"webglcontextrestored",
"webp",
"wicg",
"Winamp",
"WINTRAP",
"woah",
Expand Down
5 changes: 3 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
// eslint-disable-next-line no-unused-vars
/* global airbrush_size:writable, brush_shape:writable, brush_size:writable, button:writable, ctrl:writable, eraser_size:writable, fill_color:writable, fill_color_k:writable, history_node_to_cancel_to:writable, MenuBar:writable, my_canvas_height:writable, my_canvas_width:writable, palette:writable, pencil_size:writable, pointer:writable, pointer_active:writable, pointer_buttons:writable, pointer_over_canvas:writable, pointer_previous:writable, pointer_start:writable, pointer_type:writable, pointers:writable, reverse:writable, shift:writable, stroke_color:writable, stroke_color_k:writable, stroke_size:writable, update_helper_layer_on_pointermove_active:writable */
/* global current_history_node, default_airbrush_size, default_brush_shape, default_brush_size, default_canvas_height, default_canvas_width, default_eraser_size, default_magnification, default_pencil_size, default_stroke_size, enable_fs_access_api, file_name, get_direction, localize, magnification, main_canvas, main_ctx, remove_hotkey, return_to_tools, selected_colors, selected_tool, selected_tools, selection, showSaveFilePicker, systemHooks, textbox, transparency */
/* global current_history_node, default_airbrush_size, default_brush_shape, default_brush_size, default_canvas_height, default_canvas_width, default_eraser_size, default_magnification, default_pencil_size, default_stroke_size, enable_fs_access_api, file_name, FileSystemFileHandle, get_direction, localize, magnification, main_canvas, main_ctx, remove_hotkey, return_to_tools, selected_colors, selected_tool, selected_tools, selection, showSaveFilePicker, systemHooks, textbox, transparency */

import { $ColorBox } from "./$ColorBox.js";
import { $ToolBox } from "./$ToolBox.js";
Expand Down Expand Up @@ -840,7 +840,8 @@ $("body").on("dragover dragenter", (/** @type {JQuery.DragOverEvent | JQuery.Dra
if (!handle || handle.kind === 'file') {
let file;
try {
if (handle) {
// instanceof is for the type checker; it should be guaranteed since kind is 'file'
if (handle && handle instanceof FileSystemFileHandle) {
file = await handle.getFile();
} else {
file = item.getAsFile();
Expand Down

0 comments on commit 9870bb2

Please sign in to comment.