Skip to content

Argument of type 'ImageBitmap' is not assignable to parameter of type 'HTMLCanvasElement | HTMLImageElement | HTMLVideoElement' #25468

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

Closed
jtenner opened this issue Jul 5, 2018 · 5 comments
Assignees
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@jtenner
Copy link

jtenner commented Jul 5, 2018

Hello! I am a very huge fan of typescript, and I'm sure adding ImageBitmap to the d.ts file responsible for canvas definitions should work.

Just to be clear, MDN lists the following things for CanvasRenderingContext2D.protortype.createPattern

A CanvasImageSource to be used as the image to repeat. It can be an:

- HTMLImageElement (<img>)
- HTMLVideoElement (<video>, by using the capture of the video)
- HTMLCanvasElement (<canvas>)
- CanvasRenderingContext2D
- ImageBitmap
- ImageData
- Blob

TypeScript Version: 2.9.2

Search Terms: Canvas. ImageBitmap, createPattern

Code

const image = await createImageBitmap(blob);
const pattern = ctx.createPattern(image);

Expected behavior:

Well I expect typescript to not report this as a problem.

Actual behavior:

Currently reported like this in my IDE.

Argument of type 'ImageBitmap' is not assignable to parameter of type 'HTMLCanvasElement | HTMLImageElement | HTMLVideoElement'.
  Type 'ImageBitmap' is not assignable to type 'HTMLVideoElement'.
    Property 'msHorizontalMirror' is missing in type 'ImageBitmap'.

Playground Link:
http://www.typescriptlang.org/play/#src=%0D%0Afetch("path%2Fto%2Fimg.png")%0D%0A%20%20%20%20.then(e%20%3D>%20e.blob())%0D%0A%20%20%20%20.then(e%20%3D>%20createImageBitmap(e))%0D%0A%20%20%20%20.then(e%20%3D>%20document.createElement("canvas")%0D%0A%20%20%20%20%20%20%20%20.getContext("2d")%0D%0A%20%20%20%20%20%20%20%20.createPattern(e%2C%20"repeat-x"))%3B%0D%0A%0D%0A

Related Issues: There are a few issues that involve definitions, not sure where to put this.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Jul 5, 2018
@mhegazy mhegazy added this to the Community milestone Jul 5, 2018
@jtenner
Copy link
Author

jtenner commented Jul 6, 2018

Can I fork TypeScript and change this line?
https://github.com/Microsoft/TypeScript/blob/02547fe664a1b5d1f07ea459f054c34e356d3746/src/lib/dom.generated.d.ts#L1786

It's my understanding that this is a generated file, so my guess is probably "no."

@mhegazy
Copy link
Contributor

mhegazy commented Jul 6, 2018

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

@jtenner
Copy link
Author

jtenner commented Jul 6, 2018

@mhegazy I think I'm confused as to how to fix these files.

What's interesting is that this file notes createPattern has a parameter of CanvasImageSource. The createPattern definition is here.

https://github.com/Microsoft/TSJS-lib-generator/blob/master/inputfiles/idl/HTML%20-%20Canvas.widl#L96

  CanvasPattern? createPattern(CanvasImageSource image, [TreatNullAs=EmptyString] DOMString repetition);

However, it's properly defined here:

https://github.com/Microsoft/TSJS-lib-generator/blob/master/inputfiles/idl/HTML%20-%20Canvas.widl#L21

typedef (HTMLOrSVGImageElement or
         HTMLVideoElement or
         HTMLCanvasElement or
         ImageBitmap or
         OffscreenCanvas) CanvasImageSource;

I am unsure how to make the proper change to these files. Any ideas?

@mhegazy
Copy link
Contributor

mhegazy commented Jul 6, 2018

Looks like it is already fixed in https://github.com/Microsoft/TSJS-lib-generator. We port these regularly. so it should be in an upcoming TS release.

@mhegazy mhegazy added the Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet label Jul 6, 2018
@mhegazy mhegazy self-assigned this Jul 6, 2018
@mhegazy mhegazy modified the milestones: Community, TypeScript 3.1 Jul 6, 2018
@jtenner
Copy link
Author

jtenner commented Jul 6, 2018

Thank you!

In the meantime, my IDE still barks at me over this function. Looks like I'll have to just wait for the files to update.

Cheers.

@jtenner jtenner closed this as completed Jul 6, 2018
@mhegazy mhegazy reopened this Jul 6, 2018
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed Fixed A PR has been merged for this issue labels Jul 25, 2018
@mhegazy mhegazy removed the Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet label Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants