isaacs / node-tar

tar for node
ISC License
837 stars 183 forks source link

Typescript issues for `Pack` and base type `Minipass<ContiguousData, Buffer, WarnEvent>` when using node v18 types #417

Closed viceice closed 4 months ago

viceice commented 4 months ago
> pnpm test
node_modules/.pnpm/tar@7.1.0/node_modules/tar/dist/commonjs/pack.d.ts:70:5 - error TS2416: Property 'end' in type 'Pack' is not assignable to the same property in base type 'Minipass<ContiguousData, Buffer, WarnEvent>'.
  Type '(path?: string | ReadEntry | undefined) => this' is not assignable to type '{ (cb?: (() => void) | undefined): this; (chunk: Buffer, cb?: (() => void) | undefined): this; (chunk: Buffer, encoding?: Encoding | undefined, cb?: (() => void) | undefined): this; }'.
    Types of parameters 'path' and 'cb' are incompatible.
      Type '(() => void) | undefined' is not assignable to type 'string | ReadEntry | undefined'.
        Type '() => void' is not assignable to type 'string | ReadEntry | undefined'.

70     end(path?: string | ReadEntry): this;
       ~~~

node_modules/.pnpm/tar@7.1.0/node_modules/tar/dist/commonjs/pack.d.ts:71:5 - error TS2416: Property 'write' in type 'Pack' is not assignable to the same property in base type 'Minipass<ContiguousData, Buffer, WarnEvent>'.
  Type '(path: string | ReadEntry) => boolean' is not assignable to type '{ (chunk: Buffer, cb?: (() => void) | undefined): boolean; (chunk: Buffer, encoding?: Encoding | undefined, cb?: (() => void) | undefined): boolean; }'.
    Types of parameters 'path' and 'chunk' are incompatible.
      Type 'Buffer' is not assignable to type 'string | ReadEntry'.
        Type 'Buffer' is missing the following properties from type 'ReadEntry': #private, header, startBlockSize, blockRemain, and 75 more.

71     write(path: string | ReadEntry): boolean;
       ~~~~~

Found 2 errors in the same file, starting at: node_modules/.pnpm/tar@7.1.0/node_modules/tar/dist/commonjs/pack.d.ts:70
Goodwine commented 4 months ago

Repro steps were provided on another thread:

https://github.com/isaacs/node-tar/issues/413#issuecomment-2087181317

isaacs commented 4 months ago

Ah, yes this is a dupe, should be fixed in 7.2

torresgol10 commented 3 months ago

I have the same problem with the version tar@7.2, @types/node@20.14.2 and typescript@5.3.3.

How can I fix it?

[tsl] ERROR in /node_modules/.pnpm/tar@7.2.0/node_modules/tar/dist/commonjs/pack.d.ts(70,5)
      TS2416: Property 'end' in type 'Pack' is not assignable to the same property in base type 'Minipass<ContiguousData, Buffer, WarnEvent>'.
  Type '(path?: string | ReadEntry | undefined) => this' is not assignable to type '{ (cb?: (() => void) | undefined): this; (chunk: Buffer, cb?: (() => void) | undefined): this; (chunk: Buffer, encoding?: Encoding | undefined, cb?: (() => void) | undefined): this; }'.
    Types of parameters 'path' and 'cb' are incompatible.
      Type '(() => void) | undefined' is not assignable to type 'string | ReadEntry | undefined'.
        Type '() => void' is not assignable to type 'string | ReadEntry | undefined'.

ERROR in /node_modules/.pnpm/tar@7.2.0/node_modules/tar/dist/commonjs/pack.d.ts
71:4-9
[tsl] ERROR in /home/user/next.js/node_modules/.pnpm/tar@7.2.0/node_modules/tar/dist/commonjs/pack.d.ts(71,5)
      TS2416: Property 'write' in type 'Pack' is not assignable to the same property in base type 'Minipass<ContiguousData, Buffer, WarnEvent>'.
  Type '(path: string | ReadEntry) => boolean' is not assignable to type '{ (chunk: Buffer, cb?: (() => void) | undefined): boolean; (chunk: Buffer, encoding?: Encoding | undefined, cb?: (() => void) | undefined): boolean; }'.
    Types of parameters 'path' and 'chunk' are incompatible.
      Type 'Buffer' is not assignable to type 'string | ReadEntry'.
        Type 'Buffer' is missing the following properties from type 'ReadEntry': #private, header, startBlockSize, blockRemain, and 75 more.
stephematician commented 2 months ago

I have the same problem with the version tar@7.2, @types/node@20.14.2 and typescript@5.3.3.

How can I fix it?

Same here, typescript @5.5.3, @types/node@20.14.9, and tar@7.4.0.

isaacs commented 2 months ago

Reproduction case, please. This works fine for me.

isaacs commented 2 months ago

Actually, no, this issue is for tar 7.1, minipass 5, and @types/node v18.

@stephematician @pamelalozano16 Whatever problems you're having, they're not this issue, even if the error looks similar. Open a new issue with full detailed steps to reproduce what you are seeing, and I will gladly take a look.