Skip to content

Commit 3ff2010

Browse files
committed
fix(unzip): fix Yauzl typings
Both `open` and `openReadStream` have overloads, so `promisify` can't know which one to choose and chooses the last one (which doesn't include options). Additionally, once we specify those two overloads, optional args become `arg | undefined` which is subtly different than not providing an arg (which is what we want to be able to do), so we specify onEntry's `openReadStream` callback explicitly as well (to have options be optional). I think this last point is also why we can't just update `yauzl`'s types to have both `options` and `callback` be optional, because `options` when `promisified` will be unioned with `undefined`, not optional (meaning you can't just leave it off, you'd have to actually pass `undefined` as the value if you want to use it). microsoft/TypeScript#13570 microsoft/TypeScript#13195
1 parent 03e8121 commit 3ff2010

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib"
3+
}

src/android/utils/.apk.ts.swp

12 KB
Binary file not shown.

src/utils/unzip.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Readable } from 'stream';
22
import { promisify } from 'util';
3-
import { Entry, Options, ZipFile } from 'yauzl';
3+
import { Entry, Options, ZipFile, ZipFileOptions } from 'yauzl';
44

5-
// Override so promisify typing correctly infers params
6-
export type YauzlOpenReadStream = (entry: Entry, callback?: (err: Error, stream: Readable) => void) => Promise<Readable>;
7-
type YauzlOpen = (path: string, options: Options, callback?: (err: Error, zipfile: ZipFile) => void) => void;
8-
type UnzipOnEntry = (entry: Entry, zipfile: ZipFile, openReadStream: YauzlOpenReadStream) => void;
5+
// Specify which of possible overloads is being promisified
6+
type YauzlOpenReadStream = (entry: Entry, options?: ZipFileOptions, callback?: (err: Error, stream: Readable) => void) => void;
7+
type YauzlOpen = (path: string, options?: Options, callback?: (err: Error, zipfile: ZipFile) => void) => void;
8+
type UnzipOnEntry = (entry: Entry, zipfile: ZipFile, openReadStream: (arg1: Entry, arg2?: ZipFileOptions) => Promise<Readable>) => void;
99

1010
export async function unzip(srcPath: string, onEntry: UnzipOnEntry) {
1111
const yauzl = await import('yauzl');

0 commit comments

Comments
 (0)