Skip to content

'colorSpace' missing from the declaration of ImageData #2383

Open
@VittorioAccomazzi

Description

@VittorioAccomazzi

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):
├── [email protected]
└─┬ [email protected]
  └─┬ [email protected]
    └─┬ @jest/[email protected]
      └─┬ [email protected]
        └─┬ [email protected]
          └─┬ [email protected]
            └── [email protected] deduped
  • Environment (e.g. node 20.9.0 on macOS 14.1.1): v20.12.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions