0

I have Angular project that has generated web-worker with attached canvas to it using transferControlToOffscreen. Everything went well until I needed to create another OffscreenCanvas inside the web-worker. Now the build is throwing TS2304: Cannot find name 'OffscreenCanvas'..

I believe it's something with tsconfig file but I can't for life figure out what it is exactly.

tsconfig.worker.json:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/worker",
    "lib": [
      "es2018",
      "webworker"
    ],
    "types": []
  },
  "include": [
    "src/**/*.worker.ts"
  ]
}

tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "downlevelIteration": true,
    "importHelpers": true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2018",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es7",
      "dom"
    ],
    "module": "esnext",
    "baseUrl": "./"
  },
  "filesGlob": [
    "./src/**/*.ts",
    "./test/**/*.ts",
    "!./node_modules/**/*.ts",
    "src/custom_typings.d.ts",
    "typings/browser.d.ts"
  ]
}
  • Maybe you should post some code too. I have never used 'filesGlob', you could try to exclude "src/**/*.worker.ts" there. – Josef Jun 10 '20 at 07:31
  • There's nothing to post really. I'm just creating a variable inside a worker on which I just assign a value of `new OffscreenCanvas(0, 0)`. That's it. – Igor Vinogradov Jun 10 '20 at 07:35
  • @SuperKeksmann what I found out is that if I slap a `@ts-ignore` on the line, where I use the `OffscreenCanvas` class - it works. Not only it builds - it creates the object. But I strongly feel like it's a hack – Igor Vinogradov Jun 10 '20 at 07:55
  • It seems like the compiler thinks the worker module is a standart ts-module, have you tried to exclude `"src/**/*.worker.ts"` in the default `tsconfig`? – Josef Jun 10 '20 at 08:00
  • @SuperKeksmann it's already excluded in `tsconfig.app.json` – Igor Vinogradov Jun 10 '20 at 08:22

0 Answers0