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

Cannot find name DedicatedWorkerGlobalScope #12922

Closed
F3n67u opened this issue Nov 28, 2021 · 3 comments
Closed

Cannot find name DedicatedWorkerGlobalScope #12922

F3n67u opened this issue Nov 28, 2021 · 3 comments

Comments

@F3n67u
Copy link
Contributor

F3n67u commented Nov 28, 2021

I tried implement worker_threads.isMainThread via DedicatedWorkerGlobalScope, but deno complain cannot find name DedicatedWorkerGlobalScope ;

// test.ts
const isMainThread = typeof DedicatedWorkerGlobalScope === "undefined" ||
  self instanceof DedicatedWorkerGlobalScope === false;
console.log(isMainThread);
% deno run test.ts 
Check file:///Users/feng/dev/deno/test-ts/test.ts
error: TS2304 [ERROR]: Cannot find name 'DedicatedWorkerGlobalScope'.
const isMainThread = typeof DedicatedWorkerGlobalScope === "undefined" ||
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~
    at file:///Users/feng/dev/deno/test-ts/test.ts:1:29

TS2304 [ERROR]: Cannot find name 'DedicatedWorkerGlobalScope'.
  self instanceof DedicatedWorkerGlobalScope === false;
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
    at file:///Users/feng/dev/deno/test-ts/test.ts:2:19

Found 2 errors.
@nayeemrmn
Copy link
Collaborator

You should just // @ts-ignore that line. That symbol is only defined within workers so if you're using it to check if you're in a worker you'll have to bypass type-checking.

@bartlomieju
Copy link
Member

@F3n67u FYI there's already an open PR to add worker_threads that is feature-complete: denoland/std#1151 but we still haven't landed it due to type checking issues. I suggest not to duplicate the work and maybe instead try to figure out the type checking problems in aforementioned PR?

@F3n67u
Copy link
Contributor Author

F3n67u commented Nov 28, 2021

@F3n67u FYI there's already an open PR to add worker_threads that is feature-complete: denoland/deno_std#1151 but we still haven't landed it due to type checking issues. I suggest not to duplicate the work and maybe instead try to figure out the type checking problems in aforementioned PR?

@bartlomieju ok, thanks for your information. I will set isMainThread as true when it's used in the node test now. It's ok when the node test is not related to worker.

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

3 participants