question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type declaration of CanvasImageSource in lib.webworker.d.ts is incomplete.

See original GitHub issue

Type declaration of CanvasImageSource in lib.webworker.d.ts is now only ImageBitMap. But that should be HTMLOrSVGImageElement | HTMLVideoElement | HTMLCanvasElement | ImageBitmap https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource

TypeScript Version: 3.4.0-dev.201190216

Search Terms: CanvasImageSource

Code

let ctx = document.createElement("canvas").getContext("2d")
let img = new Image()
ctx.drawImage(img, 0, 0)

tsconfig.json

{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "lib": [
      "webworker",
      "es2018",
      "dom",
    ]
  }
}

whole project in https://github.com/Muratam/yabai-sample.ts

Expected behavior: No error occurs when run webpack nor webpack --watch

Actual behavior: Following error occurs when incremental build in webpack --watch “TS2345: Argument of type ‘HTMLImageElement’ is not assignable to parameter of type ‘ImageBitmap’. Property ‘close’ is missing in type ‘HTMLImageElement’ but required in type ‘ImageBitmap’”

Playground Link:

Related Issues: #25468 In that issue, only TypeScript/src/lib/dom.generated.d.ts is referred, but lib.webworker.d.ts is also needed to be referred. Please fix type declaration of CanvasImageSource in lib.webworker.d.ts

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Fabianopbcommented, Apr 17, 2019

@saschanaz I’ve tried his example with "skipDefaultLibCheck": true and the error persisted (in incremental builds with --watch as @kazakami mentioned).

However, it didn’t raise any errors when lib is defined as

{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "lib": [
      "es2018",
      "dom",
      "webworker",
    ]
  }
}

(notice that I’ve placed webworker after dom)

So my question is, does the order matter here?

1reaction
Fabianopbcommented, Mar 11, 2019

I started checking the issue in TSJS lib generator, and exposing CanvasImageSource with the required type to webworker means that we would need to bring along a whole chain of types and interfaces currently unknown to webworker and that CanvasImageSource depend on.

For example, HTMLOrSVGImageElement depends on the interface HTMLImageElement, which extends HTMLElement and so on and so forth. The chain looks really long…

Did I get this right? By doing this we would bring dozens of types and interfaces to webworker.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to construct 'Worker': Module scripts are not supported ...
node_modules/typescript/lib/lib.webworker.d.ts(4335,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'self' ...
Read more >
Duplicate definitions in lib.dom.d.ts and lib.webworker.d.ts
Duplicate definitions in lib.dom.d.ts and lib.webworker.d.ts ... I need the dom library for definitions of 'window', and the worker one for ... Type,...
Read more >
TypeScript: lib/lib.webworker.d.ts - Fossies
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found