Automattic / Automattic/node-canvas

'colorSpace' missing from the declaration of ImageData

Open
#2,383 0 comments 8 reactions 0 assignees View on GitHub
Feature
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

## Issue
The DOM definition of `ImageData` right now includes a new field called [colorSpace](https://developer.mozilla.org/en-US/docs/Web/API/ImageData/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:
``` typescript
export default function cropImage(imageData : ImageData ) : ImageData {
return imageData;
}
```
4. under the `src` folder create `cropImage.test.ts` as follow:
``` typescript
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();
})
});
```
5. 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.