From 6bfce29af61fad344a56d74b862a24fc8cec18ce Mon Sep 17 00:00:00 2001 From: ergunsh Date: Fri, 10 Sep 2021 14:08:21 +0200 Subject: [PATCH] Improve typing of `Image.encode` Instead of returning `any` we're now returning the whole object. Still from typing perspective, the API is not that great since we don't have any type relation between `encode` calls and `encodedWith` property. Maybe we can think about returning directly from `encode` call with the returned object having properties that is supplied in `encode` calls --- libsquoosh/src/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libsquoosh/src/index.ts b/libsquoosh/src/index.ts index bfd3bac1..cc4fe1af 100644 --- a/libsquoosh/src/index.ts +++ b/libsquoosh/src/index.ts @@ -26,6 +26,12 @@ type PreprocessOptions = { quant?: QuantOptions; rotate?: RotateOptions; }; +type EncodeResult = { + optionsUsed: object; + binary: Uint8Array; + extension: string; + size: number; +}; async function decodeFile({ file, @@ -83,7 +89,7 @@ async function encodeImage({ encConfig: any; optimizerButteraugliTarget: number; maxOptimizerRounds: number; -}) { +}): Promise { let binary: Uint8Array; let optionsUsed = encConfig; const encoder = await encoders[encName].enc(); @@ -172,7 +178,7 @@ class Image { public file: ArrayBuffer | ArrayLike; public workerPool: WorkerPool; public decoded: Promise<{ bitmap: ImageData }>; - public encodedWith: { [key: string]: any }; + public encodedWith: { [key in EncoderKey]?: Promise }; constructor( workerPool: WorkerPool,