octet-stream / form-data

Spec-compliant FormData implementation for Node.js
https://www.npmjs.com/package/formdata-node
MIT License
142 stars 17 forks source link

formdata-node 4.2.0 is incompatible with form-data-encoder 1.5.1 #45

Closed lantw44 closed 3 years ago

lantw44 commented 3 years ago

I just copied the code from the example 7, and it failed to compile:

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "moduleResolution": "node",
    "lib": ["ES2020"],
    "rootDir": "src",
    "outDir": "dist",
    "sourceMap": true,
    "declaration": true,
    "declarationMap": true,
    "strict": true,
    "esModuleInterop": true
  }
}

src/test.ts

import {Encoder} from "form-data-encoder"
import {FormData} from "formdata-node"

const form = new FormData()
const encoder = new Encoder(form)

formdata-node 4.0.1 is OK.

$ npm install formdata-node@4.0 && npx tsc
+ formdata-node@4.0.1
updated 1 package and audited 8 packages in 1.462s

formdata-node 4.1.0 and 4.2.0 are not.

$ npm install formdata-node@4.1 && npx tsc
+ formdata-node@4.1.0
updated 1 package and audited 9 packages in 0.411s

src/test.ts:5:29 - error TS2345: Argument of type 'FormData' is not assignable to parameter of type 'FormDataLike'.
  The types returned by 'getAll(...)' are incompatible between these types.
    Type 'import("/tmp/tmp.kMHVqvCq9h/z/node_modules/formdata-node/@type/FormData").FormDataEntryValue[]' is not assignable to type 'import("/tmp/tmp.kMHVqvCq9h/z/node_modules/form-data-encoder/@type/FormDataLike").FormDataEntryValue[]'.
      Type 'import("/tmp/tmp.kMHVqvCq9h/z/node_modules/formdata-node/@type/FormData").FormDataEntryValue' is not assignable to type 'import("/tmp/tmp.kMHVqvCq9h/z/node_modules/form-data-encoder/@type/FormDataLike").FormDataEntryValue'.
        Type 'File' is not assignable to type 'FormDataEntryValue'.
          Type 'File' is not assignable to type 'FileLike'.
            The types returned by 'stream()[Symbol.asyncIterator](...)' are incompatible between these types.
              Property '[Symbol.asyncIterator]' is missing in type 'ReadableStreamAsyncIterator<Uint8Array>' but required in type 'AsyncIterableIterator<Uint8Array>'.

5 const encoder = new Encoder(form)
                              ~~~~

  node_modules/typescript/lib/lib.es2018.asynciterable.d.ts:44:5
    44     [Symbol.asyncIterator](): AsyncIterableIterator<T>;
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '[Symbol.asyncIterator]' is declared here.

Found 1 error.
$ npm install formdata-node@4.2 && npx tsc
+ formdata-node@4.2.0
updated 1 package and audited 9 packages in 0.41s

src/test.ts:5:29 - error TS2345: Argument of type 'FormData' is not assignable to parameter of type 'FormDataLike'.
  The types returned by 'getAll(...)' are incompatible between these types.
    Type 'import("/tmp/tmp.kMHVqvCq9h/z/node_modules/formdata-node/@type/FormData").FormDataEntryValue[]' is not assignable to type 'import("/tmp/tmp.kMHVqvCq9h/z/node_modules/form-data-encoder/@type/FormDataLike").FormDataEntryValue[]'.
      Type 'import("/tmp/tmp.kMHVqvCq9h/z/node_modules/formdata-node/@type/FormData").FormDataEntryValue' is not assignable to type 'import("/tmp/tmp.kMHVqvCq9h/z/node_modules/form-data-encoder/@type/FormDataLike").FormDataEntryValue'.
        Type 'File' is not assignable to type 'FormDataEntryValue'.
          Type 'File' is not assignable to type 'FileLike'.
            The types returned by 'stream()[Symbol.asyncIterator](...)' are incompatible between these types.
              Property '[Symbol.asyncIterator]' is missing in type 'ReadableStreamAsyncIterator<Uint8Array>' but required in type 'AsyncIterableIterator<Uint8Array>'.

5 const encoder = new Encoder(form)
                              ~~~~

  node_modules/typescript/lib/lib.es2018.asynciterable.d.ts:44:5
    44     [Symbol.asyncIterator](): AsyncIterableIterator<T>;
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '[Symbol.asyncIterator]' is declared here.

Found 1 error.

Installed packages:

$ npm ls
/z
├── @types/node@14.17.15
├── fetch-blob@2.1.2
├── form-data-encoder@1.5.1
├─┬ formdata-node@4.2.0
│ ├── node-domexception@1.0.0
│ └── web-streams-polyfill@4.0.0-beta.1
└── typescript@4.4.2
octet-stream commented 3 years ago

Hi, thanks for your feedback. I will take a look, but it seems like more of a form-data-encoder issue, because it didn't catch up with the latest changes. In formdata-node v4.1.0 I've introduced in-house implementation of Blob, which is basically a port of fetch-blob@3 and it use ReadableStreams. I just need to update form-data-encoder to support it.

octet-stream commented 3 years ago

For now just switch back to 4.0.1, it should not make any difference for you.

octet-stream commented 3 years ago

This update should fix your issue: https://github.com/octet-stream/form-data-encoder/releases/tag/v1.5.2

lantw44 commented 3 years ago

Yes, it is fixed. I think we can close the issue.