diff options
Diffstat (limited to 'src/lib/Saving.ts')
| -rw-r--r-- | src/lib/Saving.ts | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/lib/Saving.ts b/src/lib/Saving.ts index 0d71057..8017fd1 100644 --- a/src/lib/Saving.ts +++ b/src/lib/Saving.ts @@ -8,18 +8,19 @@ export function save(grid: Grid) { a.download = "sudoku-save.json"; a.click(); } -export function readGridFromFile(f: File): Promise<string[][] | null> { +export function readGridFromFile(f?: File): Promise<string[][] | null> { return new Promise(res => { let reader = new FileReader(); reader.onload = e => { try { - //@ts-expect-error - const json = JSON.parse(e.target.result); - res(json) + if (typeof e.target?.result === "string") + res(JSON.parse(e.target.result)) + else + res(null) } catch (error) { res(null) } }; - reader.readAsText(f); + f ? reader.readAsText(f) : f; }) } |
