tesseract.js icon indicating copy to clipboard operation
tesseract.js copied to clipboard

Cannot access ambient const enums when the '--isolatedModules' flag is provided

Open luaneko opened this issue 5 years ago • 3 comments

Describe the bug This error occurs when attempting to use tesseract.js typescript enums which are defined as const enum. This prevents these enums from being used in popular frameworks such as create-react-app.

Specifically: OEM and PSM enums.

To Reproduce Steps to reproduce the behavior:

  1. Set up a create-react-app project and install tesseract.js.
  2. Attempt to initialize a worker with an OEM mode.

Expected behavior Code compiles.

Screenshots image

Desktop (please complete the following information): Inapplicable

Smartphone (please complete the following information): Inapplicable

Additional context Possible solution is to remove const from these enums.

luaneko avatar Apr 04 '20 14:04 luaneko

I am aware of simply using integers because these are const enums. However, since this library is providing an enum definition anyway, referring to enums by name should be preferred over magic numbers.

luaneko avatar Apr 04 '20 14:04 luaneko

Can you share the full example code to reproduce this issue?

jeromewu avatar Apr 26 '20 06:04 jeromewu

Hello. It has been almost 2 years but this problem still persists. Reported reproduction steps look good to me but if you still need an example, I have created a project using react example from readme and added typescript. My reproduction example. The only change I have made to the template code is adding await worker.setParameters({ tessedit_pageseg_mode: PSM.AUTO, }) to demonstrate const enum issue. Typescript has an explanation on the topic. For the time being, I removed const from those two enums and got no problems so far.

Dullson avatar Apr 07 '22 15:04 Dullson

I'm not the most knowledgeable regarding typescript, however see no reason not to remove const given the discussion above. The potential downsides with regards to inlining seems negligible. Will include in next release.

Balearica avatar Sep 21 '22 02:09 Balearica