D
Deno

help

Worker: TS2304 [ERROR]: Cannot find name 'postMessage'

Jjcayzac7/14/2023
When type-checking a worker script that uses the global postMessage() method, deno check gives a TS2304 [ERROR]: Cannot find name 'postMessage' error. Is there any workaround? deno check doesn't seem to accept any argument to specify what context the script executes in (e.g. Window vs DedicatedWorkerGlobalScope), nor can it apparently infer it based on file name conventions (*.worker.ts)
AAapoAlas7/14/2023
You'll need to use triple-slash type comment.
Jjcayzac7/14/2023
Do you mean /// @deno-types="../worker.d.ts" and declare postMessage() in that file? Doesn't the /// comment only works on imports, tho? I'm not importing anything. Also, it just occured to me that a global postMessage() isn't specific to workers, and exists on the Window interface too. It's weird that Deno doesn't have it.
AAapoAlas7/14/2023
No, I meant including (I think) lib.webworker.d.ts which should maybe have the definitions globally available. Maybe.
Jjcayzac7/20/2023
Thanks, it's actually mentioned in the docs and I missed it. https://deno.land/manual@v1.35.2/advanced/typescript/types#using-triple-slash-directives
Deno
Types and Type Declarations | Manual | Deno
One of the design principles of Deno is no non-standard module resolution. When TypeScript is type checking a file, it only cares about the types for the file, and the tsc compiler has a lot of log
Jjcayzac7/20/2023
/// <reference no-default-lib="true" />
/// <reference lib="deno.worker" />
/// <reference no-default-lib="true" />
/// <reference lib="deno.worker" />
It would be neat if lib could be assigned per file pattern, inthe json configuration (so that I could have the default lib everywhere but use deno.worker for *.worker.ts)

Looking for more? Join the community!

Recommended Posts
How to recover from worker death? It terminates my main program…In the error message handler, I replace the dead worker with a new one, but it kills my program eithIs there anyone using kv with pentagon ORM and Zod ?I've tried using pentagon for Deno kv in a Fresh project, and it seems like it's not working.Prefix Kv keys with a base partCurrently I add `base()` to all keys: ``` kv.set([base(), "foo"], value) ``` Instead of manually adCaching old versionsWhy is deno caching old versions even tho the version is specifieddeno check: Module '"internal:///missing_dependency.d.ts"' has no exported member...The sequence of events: - Upgraded to Deno 1.35.0 - ran `deno check` on my code - got an error like cargo compile size 160MWhen using `cargo install deno` the result is 160M, if there's info on shrinking this somewhere pleaDeno type enforcementHey, I have a question about the type checking. ```ts function logging(message : number) { consoDNS Records and Denoso I am confused I'm building an application that uses Steam's web API and am looking at why the resFresh pattern helpCould anyone possibly help guide me to understand the 'freshest' pattern for the following, please? Deno seems to assume wrong return type (Puppeteer)With the following code, I get an type error which I do not expect: ```ts const element: ElementHanCreating my first Deno moduleHave never published to NPM or Denoland before, so I'm having some problems figuring shit out. I'm gSanitize multiple test stepsIs it possible to sanitize multiple steps inside of one test. I want to test my DB with somthing likFFI string corrupted?Is there anything i'm doing wrong here? I'm confused on why it's crashing on setVerisonUE5 in particTypescript Conditional Type ReturnsI don't know why but this conditional type return is just causing me grief. ```ts type InnerType<T>Parsing Hostname for TLD, domain name, and SLDdoes anyone know of any packages to parse a URL's hostname for the top level domain, domain name, anMigrating large Node project to DenoIs there any reliable way to migrate a Node project to Deno? Currently working on a large project thWhy does Deno.serve not return a promise anymore?Doesn't this cause problems for error handling?Changing GitHub username – what about deno.land/x?If I change my GitHub username and I have a couple of modules on deno.land/x, what will happen to th