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

[Bug]: error TS2315: Type 'Uint8Array' is not generic. #19152

Open
JHarrisGTI opened this issue Dec 2, 2024 · 6 comments
Open

[Bug]: error TS2315: Type 'Uint8Array' is not generic. #19152

JHarrisGTI opened this issue Dec 2, 2024 · 6 comments

Comments

@JHarrisGTI
Copy link

Attach (recommended) or Link to PDF file

n/a

Web browser and its version

NodeJS version 20.14.0-23.3.0

Operating system and its version

MacOS 15.1.1

PDF.js version

4.9.124

Is the bug present in the latest PDF.js version?

Yes

Is a browser extension

No

Steps to reproduce the problem

  1. Install Angular CLI: npm install -g @angular/cli
  2. Make a new Angular project with ng new UInt8ArrayBug --default
  3. cd UInt8ArrayBug
  4. npm run start to verify that the Angular app starts, then ctrl-C to exit
  5. npm install --save pdfjs-dist
  6. Open src/app/app.component.ts. Inside class AppComponent add document?: PDFDocumentProxy
  7. npm run start again

What is the expected behavior?

Angular app should run.

What went wrong?

Angular doesn't start when pdfjs-dist 4.9.124 is installed and referenced.

Link to a viewer

No response

Additional context

As of version 4.9.124, pdfjs-dist throws several copies of error TS2315: Type 'Uint8Array' is not generic.

In the console, I see snippets like this:

Promise<Uint8Array<any>>;
...
Promise<Uint8Array<ArrayBuffer>>;
...
Promise<Uint8Array<ArrayBufferLike>>;

I'm not sure what changed to cause the error. Looking over the most recent patch notes, I see #19000 - perhaps that's related somehow?

As a workaround, in tsconfig.json we've set:

{
  "compilerOptions": {
    "skipLibCheck": true
  }
}

skipLibCheck tells TypeScript to skip type checking of dependencies like pdf.js. This should keep the issue at bay until our app needs to interact with the code that's throwing type errors.

@nicolo-ribaudo
Copy link
Contributor

Can you create a reproduction without angular?

@PeterStaev
Copy link

Just hit this problem as well. Seems latest pdfjs uses the most recent TS version (5.7), which introduced those generic types. While Angular (even v19) doesn't support 5.7 yet:
image
The issue can be easily reproduced in the TS playground when you select a lower version that 5.7: https://www.typescriptlang.org/play/?ts=5.6.3#code/MYewdgzgLgBAHgLhjAqgSzFAHAQQE54CGAngDz5HEBCArgGZ0CmeAMmgNaMB8MAvDGEYB3VBmwUSACgCUAbiA

Instead of disabling type check for all libs via the workaround OP suggested, you can also install a pre 4.9 version of pdfjs-dist while we wait for Angular to ship TS 5.7 support.

@levan-dolidze
Copy link

I have the same issue, "skipLibCheck": true is solving compilation error but have this kinde of error Error: No "GlobalWorkerOptions.workerSrc" specified, i donot need to use worker at all, will it]d be posaable to use withour worker , actually nee dto convert pdf into image

@JHarrisGTI
Copy link
Author

@levan-dolidze GlobalWorkerOptions.workerSrc is a separate issue. There are some suggestions for solving it in #17245.

@Snuffleupagus
Copy link
Collaborator

Is it possible for TypeScript to generate some kind of "compatibility" or "legacy" types, with better support for older environments?

As mentioned in #19000 (comment), we don't really want to get stuck on an older (and slightly arbitrary) TypeScript version.

@nicolo-ribaudo
Copy link
Contributor

For Babel, we have a copy-pasted version of the .d.ts file generated with an old TypeScript version. We point to it in "types", and use "typeVersions" to point remap them to new definitions that include new TypeScript features: https://github.com/babel/babel/blob/5d7469372ce0c3676153f019fe8f0e5998cdee54/packages/babel-types/package.json#L18-L25

This means that users on an old TypeScript version don't get types for new features, but at least they don't get errors when updating.

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

No branches or pull requests

5 participants