Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad types when building with TSC #850

Closed
SomeAspy opened this issue Nov 13, 2023 · 2 comments
Closed

Bad types when building with TSC #850

SomeAspy opened this issue Nov 13, 2023 · 2 comments

Comments

@SomeAspy
Copy link

SomeAspy commented Nov 13, 2023

Tesseract.js version 5.0.3

Describe the bug
When building with TSC (with a very simple example pictured) there seems to be several missing types.
image

The built code does indeed work, but the errors in TSC are there nonetheless, so I'm making this bug report
I found this bug after some package updates on a repo I maintain, but after backtracking the issue was still there oddly. I'm not sure what changed since last week and this week, and (as shown in the image) was checking if it was @types/node, which it did not seem to be. (it could totally be something in the package lock, not sure. I didn't dive that deep)

To Reproduce
Steps to reproduce the behavior:

  1. Install basic typescript dependencies and tesseract.js
  2. Build any code that imports members of tesseract.js
  3. TSC will report 7 errors.

Expected behavior
TSC should not report any errors

Device Version:

  • Arch Linux
  • Node v21.1.0
  • typescript@5.2.2
  • tesseract.js@5.0.3
  • @types/node@20.9.0

(reproduced on debian w/ node 20.5.1 as well)

Additional context
N/A

@Balearica
Copy link
Collaborator

A minimal Typescript example with Tesseract.js can be found here. Tesseract.js supports both browsers and Node.js, with only slight differences between the versions. The types file includes types from both. It looks like the issue here is that you are building a project for Node.js, and the compiler is throwing an error for all of the types that only exist for browsers.

Based on my very limited understanding of Typescript, I believe that this is probably an issue with the project/build configuration, and that the tsconfig.json can be modified such that it does not throw errors for types that exist in browsers. However, let me know if you investigate further and find this is not the case, and that some change is required in this repo, and we can discuss further.

@SomeAspy
Copy link
Author

I've found that you are correct, this is an issue of browser only code being in an environment I had setup not to support that.
in my tsconfig.json I had

{
	"compilerOptions:{
		...
		"lib": [
      		"ESNext",
    	],
    	...
	}
}

Adding "DOM" to the list of typescript libraries corrects the issue.
I'm not sure why I was not getting this error a week ago. Thank you for the input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants