How to import Tesseract into Angular2 (TypeScript)

2020-06-18 03:05发布

问题:

I'm trying to import Tesseract into Angular2 (TypeScript). I can see it saved into the node_modules folder but when using

import { Tesseract } from '@types/tesseract.js';

it says:

[ts] Module '"c:/Users/black/Projects/projectCLI/tess/node_modules/@types/tesseract.js/index"' has no exported member 'Tesseract'.

In the index.d.ts file there is a namespace called Tesseract.

Is there some other way to import this or are we looking at this the wrong way?

I used npm install --save-dev @types/tesseract.js to install typescript Tesseract.

If there are any demo tutorials using tesseract can you please link them here?

thanks, in advance, for your help.

回答1:

You need to install the actual javascript module:
npm install tesseract.js --save

Also install @types declarations:
npm install @types/tesseract.js --save-dev

Finally do the folowing to import:
import * as Tesseract from 'tesseract.js'

To use the library check here

The @types command saves this type declaration file.
This is a namespace and all the contents of the actual module are declared within.When you do import * as aliasname from tessreact.js, you can use all the functions within the namespace as aliasname.functionname. Example is the test file for the same type declaration file.