streamich / memfs

JavaScript file system utilities
http://streamich.github.io/memfs/
Apache License 2.0
1.75k stars 130 forks source link

Type incompatibility for `writeFile` #1022

Open michaelfaith opened 7 months ago

michaelfaith commented 7 months ago

Originally reported in the webpack repo: https://github.com/webpack/webpack/issues/18242 this appears to actually be a broken type here. When trying to assign an IFs object to a prop of fs type, we get an error about writeFile and the WriteFileOptions type not matching. Seems like the overloads are off a bit.

Type 'IFs' is not assignable to type 'OutputFileSystem'.
  Types of property 'writeFile' are incompatible.
    Type '{ (id: TFileId, data: TData, callback: TCallback<void>): any; (id: TFileId, data: TData, options: string | IWriteFileOptions, callback: TCallback<...>): any; }' is not assignable to type 'WriteFile'.
      Types of parameters 'callback' and 'options' are incompatible.
        Type 'WriteFileOptions' is not assignable to type 'TCallback<void>'.
          Type 'null' is not assignable to type 'TCallback<void>'.ts(2322)
(property) Compiler.outputFileSystem: OutputFileSystem | null

Tested with the latest version of memfs (4.8.1)

G-Rath commented 7 months ago

PRs improving the types are always welcomed!