skip to Main Content

Property ‘createSyncAccessHandle’ does not exist on type ‘FileSystemFileHandle’.ts(2339)

const root = await navigator.storage.getDirectory();

const File1 = await root.getFileHandle('file.txt', { create: true });

const accessHandle = await File1.createSyncAccessHandle();

Based on the docs we have createSyncAccessHandle method but is not found, whether I am missing something

Image

2

Answers


  1. You used createSyncAccessHandle() in FileSystemDirectoryHandle: getDirectoryHandle() method but createSyncAccessHandle() is in

    FileSystemFileHandle: createSyncAccessHandle().
    

    So, i think you need to change to:

    const root = await navigator.storage.getDirectory();
    
    const Directory = await root.getDirectoryHandle('folder', {
      create: true
    });
    
    
    const File = await root.getFileHandle('file.txt', {
      create: true
    });
    
    const accessHandle = await File.createSyncAccessHandle();
    
    Login or Signup to reply.
  2. The docs state:

    The createSyncAccessHandle() method of the FileSystemFileHandle interface returns a Promise which resolves to a FileSystemSyncAccessHandle object that can be used to synchronously read from and write to a file. The synchronous nature of this method brings performance advantages, but it is only usable inside dedicated Web Workers for files within the origin private file system.

    So my question is, are you runnning this inside a Web Worker?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search