Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type 'WebAccessFS' is not assignable to type 'FileSystem | Promise<FileSystem>' #18

Open
yoursunny opened this issue Oct 7, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@yoursunny
Copy link
Contributor

WebAccess is unusable in TypeScript due to type mismatch.

import { configure, InMemory } from "@zenfs/core";
import { WebAccess } from "@zenfs/dom";

await configure({
    mounts: {
        '/M': InMemory,
        '/W': {
            backend: WebAccess,
            handle: await navigator.storage.getDirectory(),
        },
    }
});
Type '{ readonly name: "WebAccess"; readonly options: { readonly handle: { readonly type: "object"; readonly required: true; readonly description: "The directory handle to use for the root"; }; }; readonly isAvailable: () => boolean; readonly create: (options: WebAccessOptions) => WebAccessFS; }' is not assignable to type 'Backend<FileSystem, object>'.
  The types returned by 'create(...)' are incompatible between these types.
    Type 'WebAccessFS' is not assignable to type 'FileSystem | Promise<FileSystem>'.
      Type 'WebAccessFS' is missing the following properties from type 'FileSystem': ready, renameSync, statSync, openFileSync, and 9 more.

Playground Link: Provided

@james-pre james-pre added the bug Something isn't working label Oct 7, 2024
@james-pre
Copy link
Member

This seems like the type for the Async mixin did not load correctly.

Looking into it further, I find this error with IntelliSense:

Cannot find module '@zenfs/core/mixins/shared.js' or its corresponding type declarations.
  There are types at '<project>/node_modules/@zenfs/core/dist/mixins/shared.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.ts(2307)

This error only appears in the built code, not source, which may help explain why it wasn't caught earlier.

If I change the source tsconfig.json to include all the files in dist, the error goes away. This makes me believe the problem is due to Typescript not applying the tsconfig to the dist folder.

Additionally, changing the import from @zenfs/core/mixins/shared.js to @zenfs/core/dist/mixins/shared.js fixes the problem.

I will take a closer look at this, but it may take a little longer than usual due to the strangeness of the bug.

@james-pre
Copy link
Member

james-pre commented Oct 7, 2024

@yoursunny,

Could you please try to reproduce the issue with the latest version of @zenfs/core (1.0.3)? When you do, make sure the output of npm ls utilium shows [email protected] or higher.

@james-pre james-pre changed the title Type 'WebAccessFS' is not assignable to type 'FileSystem | Promise<FileSystem>' Type 'WebAccessFS' is not assignable to type 'FileSystem | Promise<FileSystem>' Oct 7, 2024
@james-pre james-pre self-assigned this Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants