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:
ergunsh
2021-09-10 14:08:21 +02:00
parent 64cad1cc23
commit 6bfce29af6

View File

@@ -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>,