diff --git a/libsquoosh/src/index.ts b/libsquoosh/src/index.ts index cc4fe1af..04792394 100644 --- a/libsquoosh/src/index.ts +++ b/libsquoosh/src/index.ts @@ -32,6 +32,14 @@ type EncodeResult = { extension: string; size: number; }; +type EncoderOptions = { + mozjpeg?: Partial; + webp?: Partial; + avif?: Partial; + jxl?: Partial; + wp2?: Partial; + oxipng?: Partial; +}; async function decodeFile({ file, @@ -221,19 +229,12 @@ class Image { * @param {object} encodeOptions - An object with encoders to use, and their settings. * @returns {Promise} - A promise that resolves when the image has been encoded with all the specified encoders. */ - async encode( + async encode( encodeOptions: { optimizerButteraugliTarget?: number; maxOptimizerRounds?: number; - } & { - mozjpeg?: Partial; - webp?: Partial; - avif?: Partial; - jxl?: Partial; - wp2?: Partial; - oxipng?: Partial; - } = {}, - ): Promise { + } & T, + ): Promise<{ [key in keyof T]: EncodeResult }> { const { bitmap } = await this.decoded; for (const [name, options] of Object.entries(encodeOptions)) { if (!Object.keys(encoders).includes(name)) { @@ -257,6 +258,7 @@ class Image { }); } await Promise.all(Object.values(this.encodedWith)); + return this.encodedWith as { [key in keyof T]: EncodeResult }; } }