streamich / unionfs

Use multiple fs modules at once
https://www.npmjs.com/package/unionfs
The Unlicense
209 stars 24 forks source link

memfs volume not compatible with 'use' method #453

Open HoldYourWaffle opened 4 years ago

HoldYourWaffle commented 4 years ago

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 commented 4 years ago

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 commented 11 months ago

@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.