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

Overloaded type for Image.getRGBAData() #633

Open
luis-c465 opened this issue Jan 28, 2024 · 0 comments
Open

Overloaded type for Image.getRGBAData() #633

luis-c465 opened this issue Jan 28, 2024 · 0 comments

Comments

@luis-c465
Copy link

Currently, the return type for getRGBAData is listed as either Uint8Array or Uint8ClampedArray.
Though by default, with no arguments passed it will return Uint8Array, and only when the option {clamped: True} is passed will Uint8ClampedArray be returned, as stated by the docs.

Can the return type of the function in index.d.ts be updated to recognize this behavior, possibly using Function Overloads?

Reason being, recently I have used this library to first crop an image then add that image to a PDF, using jsPDF which expects the image to be a Uint8Array. Though because the type is listed as either or, typescript throws an error. I was forced to use the as keyword to manually tell typescript which type it was. Which is probably not the best solution long term.

getRGBAData(options?: { clamped?: boolean }): Uint8Array | Uint8ClampedArray;

/**
* Retrieve the data of the current image as RGBA 8 bits
* The source image may be:
* * a mask (binary image)
* * a grey image (8 16 bits) with or without alpha channel
* * a color image (8 or 16 bits) with or without alpha channel in with RGB model
* @instance
* @memberof Image
* @param {object} [options]
* @param {boolean} [options.clamped] - If true, the function will return a Uint8ClampedArray
* @return {Uint8Array|Uint8ClampedArray} - Array with the data
*/
export default function getRGBAData(options = {}) {

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

1 participant