memfs icon indicating copy to clipboard operation
memfs copied to clipboard

Type incompatibility for `writeFile`

Open michaelfaith opened this issue 3 months ago • 1 comments

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)

michaelfaith avatar Apr 03 '24 19:04 michaelfaith

PRs improving the types are always welcomed!

G-Rath avatar Apr 03 '24 19:04 G-Rath