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

memfs volume not compatible with 'use' method #453

Open
HoldYourWaffle opened this issue Apr 13, 2020 · 2 comments
Open

memfs volume not compatible with 'use' method #453

HoldYourWaffle opened this issue Apr 13, 2020 · 2 comments

Comments

@HoldYourWaffle
Copy link

When I try to use a memfs Volume I get the following errors:

With strict mode:

Argument of type 'Volume' is not assignable to parameter of type 'IFS'.
  Types of property 'ftruncateSync' are incompatible.
    Type '(fd: number, len?: number | undefined) => void' is not assignable to type '(fd: number, len?: number | null | undefined) => void'.
      Types of parameters 'len' and 'len' are incompatible.
        Type 'number | null | undefined' is not assignable to type 'number | undefined'.
          Type 'null' is not assignable to type 'number | undefined'.ts(2345)

Without strict mode:

Argument of type 'Volume' is not assignable to parameter of type 'IFS'.
  The types returned by 'statSync(...)' are incompatible between these types.
    Type 'Stats<number>' is missing the following properties from type 'BigIntStats': atimeNs, mtimeNs, ctimeNs, birthtimeNsts(2345)
@G-Rath
Copy link
Collaborator

G-Rath commented Apr 13, 2020

Yeah unfortunately fixing this is pretty complicated; doubly so when you factor in the different versions of @types/node.

It's best just to cast: either when calling use or if you're keeping the Volume around assign it as an fs:

ufs
    .use(jest.requireActual('fs'))
    .use(createFsFromVolume(vol) as any) as any;

const myVolume: typeof fs = (createFsFromVolume(vol) as unknown) as typeof fs;

When I have a chance I'll revisit, but any solution will likely be a breaking change, or at least need a lot of testing & review :(

@ericmorand
Copy link

@G-Rath But isn't it one of the selling point of unionfs to actually be compatible with memfs volumes? I mean, it is in the main README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants