Skip to content

ImageData constructor has incorrect parameter (not optional where it should be) #33266

@ariccio-learn-co-alternate

Description

TypeScript Version: 3.6.2

Search Terms:
ImageData

Code

const data: ImageData = new ImageData(screenBuffer, CANVAS_WIDTH);


Argument of type 'Uint8ClampedArray' is not assignable to parameter of type 'number'.  TS2345

    365 |             
    366 |         }
  > 367 |         const data: ImageData = new ImageData(screenBuffer, CANVAS_WIDTH);
        |              

also, simplified:

const screenBufferSize = 4;

const screenBuffer: Uint8ClampedArray = new Uint8ClampedArray(screenBufferSize);

const data: ImageData = new ImageData(screenBuffer, 1);

Expected behavior:

MDN says that the height parameter is optional if the first parameter is a Uint8ClampedArray. Typescript should choose the new(array: Uint8ClampedArray, width: number, height: number): ImageData; overload, but the third param should be optional.

Actual behavior:
Typescript is choosing the new(width: number, height: number): ImageData; overload.

Playground Link:
Where's the share button?
Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions