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

'colorSpace' missing from the declaration of ImageData #2383

Open
VittorioAccomazzi opened this issue May 12, 2024 · 0 comments
Open

'colorSpace' missing from the declaration of ImageData #2383

VittorioAccomazzi opened this issue May 12, 2024 · 0 comments

Comments

@VittorioAccomazzi
Copy link

VittorioAccomazzi commented May 12, 2024

Issue

The DOM definition of ImageData right now includes a new field called colorSpace which is not present in the current definition of ImageData of node-canvas. As a result when I compile the jest test which uses node-canvas I get the following erro in typescript:

"Argument of type 'import(\"/..../node_modules/canvas/types/index\").ImageData' is not assignable to parameter of type 'ImageData'.\n  Property 'colorSpace' is missing in type 'import(\"/.../node_modules/canvas/types/index\").ImageData' but required in type 'ImageData'."

Steps to Reproduce

  1. Generate a simple react app : npx create-react-app my-app --template typescript
  2. Add node canvas for regression testing : npm i -D canvas
  3. under the src folder create cropImage.ts as follow:
export default function cropImage(imageData : ImageData ) : ImageData  {
        return imageData;
    }
  1. under the src folder create cropImage.test.ts as follow:
import cropImage from './cropImage'
import {ImageData} from 'canvas';

describe('cropImage', ()=>{
    test('shall crop the image', ()=>{
        const imgData = new ImageData(10,10);
        const resData = cropImage(imgData);
        expect(resData).not.toBeNull();
    })
});
  1. in Visual Studio code the editor will highlight imgData as invalid type (but the test passes):
Screen Shot 2024-05-12 at 11 20 50 AM

Your Environment

  • Version of node-canvas (output of npm list canvas or yarn list canvas):
├── canvas@2.11.2
└─┬ react-scripts@5.0.1
  └─┬ jest@27.5.1
    └─┬ @jest/core@27.5.1
      └─┬ jest-config@27.5.1
        └─┬ jest-environment-jsdom@27.5.1
          └─┬ jsdom@16.7.0
            └── canvas@2.11.2 deduped
  • Environment (e.g. node 20.9.0 on macOS 14.1.1): v20.12.2
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