naptha / tesseract.js

Pure Javascript OCR for more than 100 Languages 📖🎉🖥
http://tesseract.projectnaptha.com/
Apache License 2.0
34.09k stars 2.15k forks source link

Updated types to infer output formats #903

Open Balearica opened 3 months ago

Balearica commented 3 months ago

Output formats may be enabled or disabled using the output argument on worker.recognize. However, the types are currently not intelligent enough to figure out whether an output format is enabled or disabled.

For example, in the code below, img should have type string, however it instead has type string | null.

const res = await worker.recognize(imageDummy, {}, { imageColor: true });
const img = res.data.imageColor;

This is not a huge deal, as the types can be edited to either (1) hard-code the fact that img is non-null or (2) add a check in code for img being non-null, however both of these fixes are sub-optimal. Ideally, type inference would work automatically, and the type of img could be automatically inferred based on the input arguments.