Skip to content

Restrict types from Uint8Array<ArrayBufferLike> to Uint8Array<ArrayBuffer>#133

Open
ussu wants to merge 5 commits intocantoo-scribe:masterfrom
ussu:ussu/u-int-8-array-array-buffer
Open

Restrict types from Uint8Array<ArrayBufferLike> to Uint8Array<ArrayBuffer>#133
ussu wants to merge 5 commits intocantoo-scribe:masterfrom
ussu:ussu/u-int-8-array-array-buffer

Conversation

@ussu
Copy link
Copy Markdown

@ussu ussu commented Jan 26, 2026

What?

In Typescript 5.9, there is a more precise typechecking, for instance regarding ArrayBuffer vs SharedArrayBuffer, which are both an ArrayBufferLike
It seems like what pdf-lib uses can always be typed as an ArrayBuffer rather than a SharedArrayBuffer or ArrayBufferLike, so this PR aims to narrow the return types in the package to ArrayBuffer to improve compatibility with other libs

Why?

#132

How?

Updating @types/node to a recent version allows typescript to narrow down most instances of Uint8Array to Uint8Array
In functions exposed by pdf-lib, simply removing the return types explicitly set to Uint8Array ( = Uint8Array) allows typescript to correctly infer the return type to Uint8Array

Testing?

New Dependencies?

no

Screenshots

n/a

Suggested Reading?

Anything Else?

Checklist

  • I read CONTRIBUTING.md.
  • I read MAINTAINERSHIP.md#pull-requests.
  • I added/updated unit tests for my changes.
  • I added/updated integration tests for my changes.
  • I ran the integration tests.
  • I tested my changes in Node ✅ all 18 tests ok
  • I tested my changes in Deno ❌ did not manage to run tests with Deno
  • I tested my changes in the browser ✅ all 32 tests ok
  • I viewed documents produced with my changes in Adobe Acrobat, Foxit Reader, Firefox, and Chrome.
  • I added/updated doc comments for any new/modified public APIs.
  • My changes work for both new and existing PDF files.
  • I ran the linter on my changes.

@ussu ussu changed the title Restrict types from Uint8Array<ArrayBufferLike> to Uint8Array<ArrayBu… Restrict types from Uint8Array<ArrayBufferLike> to Uint8Array<ArrayBuffer> Jan 29, 2026
@ussu ussu force-pushed the ussu/u-int-8-array-array-buffer branch from e4509d7 to 6ae67fe Compare January 29, 2026 23:47
@Sharcoux
Copy link
Copy Markdown
Collaborator

Thanks for your contribution.

Can you just fix your MR to limit to what is strictly needed to achieve the goal of the PR please? I'll merge after that.

Thanks.

@ussu ussu force-pushed the ussu/u-int-8-array-array-buffer branch from 6ae67fe to bb9b566 Compare March 12, 2026 01:07
@ussu
Copy link
Copy Markdown
Author

ussu commented Mar 19, 2026

Can you just fix your MR to limit to what is strictly needed to achieve the

sure i split into a few commits:

what i am confident with:

  • actually the only change that I want is 5007bbc
  • then i suggest adding ea680ba to upgrade the version of typescript
  • yarn lint kept making this change 319bbf4

the messy part:

  • 2d7966e has a bunch of changes actually related to how fontkit is typed so i'm not sure about this one
  • a11e29b maybe reveals an issue with UPNG typing actually i'll try to have a look at UPNG soon

@ussu ussu marked this pull request as ready for review March 19, 2026 14:52
@ussu ussu force-pushed the ussu/u-int-8-array-array-buffer branch from bb9b566 to a11e29b Compare March 19, 2026 14:54
@ussu ussu requested a review from Sharcoux March 19, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants