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

Return Type of HTMLCanvasElement getContext is not clear. #845

Open
G-yhlee opened this issue May 2, 2024 · 1 comment
Open

Return Type of HTMLCanvasElement getContext is not clear. #845

G-yhlee opened this issue May 2, 2024 · 1 comment

Comments

@G-yhlee
Copy link
Contributor

G-yhlee commented May 2, 2024

Problem

  • Return type of getContext is not clear
val canvas = document.querySelector("#monadcanvas").asInstanceOf[HTMLCanvasElement]
val ctx = canvas.getContext("2d", js.Dictionary("alpha" -> true))

ctx.beginPath(); //  beginPath is not automatically recommended even though it is an internal function of ctx

Current

abstract class HTMLCanvasElement extends HTMLElement {

  // When returning to js.Dynamic, the API type required for drawing is not inferred
  def getContext(contextId: String, args: js.Any*): js.Dynamic = js.native
}

Suggest is..

[ contextId ] -> [ return type ]
"2d" -> CanvasRenderingContext2D
"webgl" or "experimental-webgl" -> WebGLRenderingContext
"webgl2" -> WebGL2RenderingContext
"webgpu" -> GPUCanvasContext
"bitmaprenderer" -> ImageBitmapRenderingContext


// This is only match when contextType value is "2d" , We need general matching function ...
def getContext(contextType: String,
      contextAttributes: js.UndefOr[js.Dictionary[js.Any]] = js.native): CanvasRenderingContext2D = js.native
      

@armanbilge
Copy link
Member

Thanks, I agree that returning js.Dynamic is strange. I think this is an API we could improve if we do #296.

For now, perhaps we can return a union type 😕

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

2 participants