mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-11 16:26:20 +00:00
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
This commit is contained in:
@@ -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<EncodeResult> {
|
||||
let binary: Uint8Array;
|
||||
let optionsUsed = encConfig;
|
||||
const encoder = await encoders[encName].enc();
|
||||
@@ -172,7 +178,7 @@ class Image {
|
||||
public file: ArrayBuffer | ArrayLike<number>;
|
||||
public workerPool: WorkerPool<JobMessage, any>;
|
||||
public decoded: Promise<{ bitmap: ImageData }>;
|
||||
public encodedWith: { [key: string]: any };
|
||||
public encodedWith: { [key in EncoderKey]?: Promise<EncodeResult> };
|
||||
|
||||
constructor(
|
||||
workerPool: WorkerPool<JobMessage, any>,
|
||||
|
||||
Reference in New Issue
Block a user