From 31b515911c6fb05d57d8f09a5077d854a019914c Mon Sep 17 00:00:00 2001 From: Edward Sammut Alessi Date: Tue, 24 Sep 2019 23:47:24 +0200 Subject: [PATCH] Fix pizzip generate return types https://github.com/open-xml-templating/pizzip/blob/master/documentation/api_pizzip/generate.md (#38573) --- types/pizzip/index.d.ts | 14 +++++++++----- types/pizzip/pizzip-tests.ts | 23 +++++++++++++++-------- types/pizzip/tsconfig.json | 3 ++- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/types/pizzip/index.d.ts b/types/pizzip/index.d.ts index bea757fd12..4de976cf50 100644 --- a/types/pizzip/index.d.ts +++ b/types/pizzip/index.d.ts @@ -14,7 +14,7 @@ declare class PizZip { * If the browser supports them, PizZip can take advantage of some "new" features : ArrayBuffer, Blob, Uint8Array. * To know if PizZip can use them, you can check the PizZip.support object. */ - static support: { + static support: { /** * true if PizZip can read and generate ArrayBuffer, false otherwise. */ @@ -36,12 +36,12 @@ declare class PizZip { /** * the ZipObjects inside the zip with the name as key. */ - files: { [key: string]: PizZip.ZipObject }; + files: { [key: string]: PizZip.ZipObject }; /** * the comment of the zip file. */ - comment: string; + comment: string; constructor(); @@ -121,7 +121,11 @@ declare class PizZip { * see https://github.com/open-xml-templating/pizzip/blob/master/documentation/api_pizzip/support.md * @param options the options to generate the zip file */ - generate(options: PizZip.GenerateOptions): PizZip.ZipObject; + generate(options?: PizZip.GenerateOptions & { type?: 'string' | 'base64' }): string; + generate(options: PizZip.GenerateOptions & { type: 'blob' }): Blob; + generate(options: PizZip.GenerateOptions & { type: 'nodebuffer' }): Buffer; + generate(options: PizZip.GenerateOptions & { type: 'arraybuffer' }): ArrayBuffer; + generate(options: PizZip.GenerateOptions & { type: 'uint8array' }): Uint8Array; /** * Delete a file or folder (recursively). @@ -351,7 +355,7 @@ declare namespace PizZip { * * @default "base64" */ - type: 'base64' | 'string' | 'uint8array' | 'arraybuffer' | 'blob' | 'nodebuffer'; + type?: 'base64' | 'string' | 'uint8array' | 'arraybuffer' | 'blob' | 'nodebuffer'; /** * The comment to use for the zip file. */ diff --git a/types/pizzip/pizzip-tests.ts b/types/pizzip/pizzip-tests.ts index d72eeb79e4..72e512a042 100644 --- a/types/pizzip/pizzip-tests.ts +++ b/types/pizzip/pizzip-tests.ts @@ -25,8 +25,6 @@ zip.file('Hello.txt', 'Hello World\n') .remove('css'); zip.load('content', { decodeFileName: bytes => 'encoding' }); -zip.generate({ type: 'uint8array', encodeFileName: string => new Buffer('') }); -zip.generate({ type: 'blob', mimeType: 'application/ods', compression: 'DEFLATE' }); zip.file(/file/).map(z => z); zip.folder(/^vid/).map(z => z); zip.filter((relativePath, file) => true).map(z => z); @@ -35,10 +33,19 @@ zip.folder('subfolder').load('data'); const file = zip.file(''); if (file) { - file.name.split(''); - file.asText(); - file.asArrayBuffer(); - file.asUint8Array(); - file.asNodeBuffer(); - file.asText(); + const nameTest: string = file.name; + const textTest: string = file.asText(); + const binaryTest: string = file.asBinary(); + const arrBufTest: ArrayBuffer = file.asArrayBuffer(); + const uint8Test: Uint8Array = file.asUint8Array(); + const bufTest: Buffer = file.asNodeBuffer(); } + +const noOptionsTest: string = zip.generate(); +const noTypeTest: string = zip.generate({ base64: true }); +const b64Test: string = zip.generate({ type: 'base64', compression: 'DEFLATE' }); +const stringTest: string = zip.generate({ type: 'string', encodeFileName: s => new Buffer(s) }); +const arrBufTest: ArrayBuffer = zip.generate({ type: 'arraybuffer', mimeType: '' }); +const blobTest: Blob = zip.generate({ type: 'blob', compressionOptions: { level: 1 } }); +const bufTest: Buffer = zip.generate({ type: 'nodebuffer', platform: 'DOS' }); +const unit8Test: Uint8Array = zip.generate({ type: 'uint8array', base64: true }); diff --git a/types/pizzip/tsconfig.json b/types/pizzip/tsconfig.json index 79ed073852..07660a07fb 100644 --- a/types/pizzip/tsconfig.json +++ b/types/pizzip/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6" + "es6", + "dom" ], "noImplicitAny": true, "noImplicitThis": true,