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

deno lsp, deno-ts: Property 'postMessage' does not exist on type 'Window & typeof globalThis'.deno-ts(2339) #9696

Open
starkpsmichael opened this issue Mar 5, 2021 · 10 comments
Labels
feat new feature (which has been agreed to/accepted) lsp related to the language server

Comments

@starkpsmichael
Copy link

starkpsmichael commented Mar 5, 2021

Using deno canary, latest stable vscode and vscode-deno ext.

Don't know who produce this problem but i'm trying to solve the problem that some type definitions aren't available in webworkers:

Create a file called a.ts

const worker = new Worker(new URL("./b.ts", import.meta.url).href, {
  type: "module",
});

worker.addEventListener("message", (b) => {
  globalThis.console.log(b);
});

Create a file called b.ts

self.postMessage("1");

deno run a.ts works - with no errors, but hovering over postMessage gives:
Property 'postMessage' does not exist on type 'Window & typeof globalThis'.deno-ts(2339)

Trying to solve this with a tripple slash directive at the top of the file:

/// <reference lib="webworker" />
self.postMessage("1"); // Hovering works now
but `deno run` now gives the following errors:
deno run --allow-read a.ts
Check file:///workspaces/fk/b.ts
error: Uncaught (in worker "") TS6200 [ERROR]: Definitions of the following identifiers conflict with those in another file: DOMException, Event, EventTarget, EventListenerOrEventListenerObject, ProgressEvent, TextDecoder, TextEncoder, AbortController, URLSearchParams, URL
interface AddEventListenerOptions extends EventListenerOptions {
~~~~~~~~~
    at asset:///lib.webworker.d.ts:25:1

    Conflicts are in this file.
    declare class DOMException extends Error {
    ~~~~~~~
        at asset:///lib.deno.web.d.ts:8:1

TS6200 [ERROR]: Definitions of the following identifiers conflict with those in another file: Global, Instance, Memory, Module, Table, ImportExportKind, TableKind, ValueType, ExportValue, Exports, ImportValue, ModuleImports, Imports, BufferSource, MessageEvent, ErrorEvent, Worker, PerformanceEntryList, Performance, PerformanceEntry, PerformanceMark, PerformanceMeasure, CustomEvent
interface AddEventListenerOptions extends EventListenerOptions {
~~~~~~~~~
    at asset:///lib.webworker.d.ts:25:1

    Conflicts are in this file.
    declare namespace WebAssembly {
    ~~~~~~~
        at asset:///lib.deno.shared_globals.d.ts:13:1

TS6200 [ERROR]: Definitions of the following identifiers conflict with those in another file: ReadableStreamReader, CountQueuingStrategy, ByteLengthQueuingStrategy, BlobPart, Blob, File, FormDataEntryValue, FormData, HeadersInit, Headers, RequestInfo, RequestCache, RequestCredentials, RequestMode, RequestRedirect, ReferrerPolicy, BodyInit, RequestDestination, Request, ResponseType, Response
interface AddEventListenerOptions extends EventListenerOptions {
~~~~~~~~~
    at asset:///lib.webworker.d.ts:25:1

    Conflicts are in this file.
    interface DomIterable<K, V> {
    ~~~~~~~~~
        at asset:///lib.deno.fetch.d.ts:8:1

TS2300 [ERROR]: Duplicate identifier 'CloseEvent'.
interface CloseEvent extends Event {
          ~~~~~~~~~~
    at asset:///lib.webworker.d.ts:965:11

    'CloseEvent' was also declared here.
    declare class CloseEvent extends Event {
                  ~~~~~~~~~~
        at asset:///lib.deno.websocket.d.ts:14:15

TS2300 [ERROR]: Duplicate identifier 'CloseEvent'.
declare var CloseEvent: {
            ~~~~~~~~~~
    at asset:///lib.webworker.d.ts:980:13

    'CloseEvent' was also declared here.
    declare class CloseEvent extends Event {
                  ~~~~~~~~~~
        at asset:///lib.deno.websocket.d.ts:14:15

TS2300 [ERROR]: Duplicate identifier 'DedicatedWorkerGlobalScope'.
interface DedicatedWorkerGlobalScope extends WorkerGlobalScope, AnimationFrameProvider {
          ~~~~~~~~~~~~~~~~~~~~~~~~~~
    at asset:///lib.webworker.d.ts:1304:11

    'DedicatedWorkerGlobalScope' was also declared here.
    declare class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
        at asset:///lib.deno.worker.d.ts:42:15

TS2300 [ERROR]: Duplicate identifier 'DedicatedWorkerGlobalScope'.
declare var DedicatedWorkerGlobalScope: {
            ~~~~~~~~~~~~~~~~~~~~~~~~~~
    at asset:///lib.webworker.d.ts:1326:13

    'DedicatedWorkerGlobalScope' was also declared here.
    declare class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
        at asset:///lib.deno.worker.d.ts:42:15

TS2430 [ERROR]: Interface 'ReadableStreamDefaultReader<R>' incorrectly extends interface 'ReadableStreamGenericReader'.
  Types of property 'closed' are incompatible.
    Type 'Promise<void>' is not assignable to type 'Promise<undefined>'.
      Type 'void' is not assignable to type 'undefined'.
interface ReadableStreamDefaultReader<R = any> extends ReadableStreamGenericReader {
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at asset:///lib.webworker.d.ts:2772:11

TS2300 [ERROR]: Duplicate identifier 'WebSocket'.
interface WebSocket extends EventTarget {
          ~~~~~~~~~
    at asset:///lib.webworker.d.ts:5324:11

    'WebSocket' was also declared here.
    declare class WebSocket extends EventTarget {
                  ~~~~~~~~~
        at asset:///lib.deno.websocket.d.ts:38:15

TS2300 [ERROR]: Duplicate identifier 'WebSocket'.
declare var WebSocket: {
            ~~~~~~~~~
    at asset:///lib.webworker.d.ts:5375:13

    'WebSocket' was also declared here.
    declare class WebSocket extends EventTarget {
                  ~~~~~~~~~
        at asset:///lib.deno.websocket.d.ts:38:15

TS2300 [ERROR]: Duplicate identifier 'WorkerGlobalScope'.
interface WorkerGlobalScope extends EventTarget, WindowOrWorkerGlobalScope {
          ~~~~~~~~~~~~~~~~~
    at asset:///lib.webworker.d.ts:5456:11

    'WorkerGlobalScope' was also declared here.
    declare class WorkerGlobalScope {
                  ~~~~~~~~~~~~~~~~~
        at asset:///lib.deno.worker.d.ts:9:15

TS2300 [ERROR]: Duplicate identifier 'WorkerGlobalScope'.
declare var WorkerGlobalScope: {
            ~~~~~~~~~~~~~~~~~
    at asset:///lib.webworker.d.ts:5482:13

    'WorkerGlobalScope' was also declared here.
    declare class WorkerGlobalScope {
                  ~~~~~~~~~~~~~~~~~
        at asset:///lib.deno.worker.d.ts:9:15

TS2300 [ERROR]: Duplicate identifier 'WorkerLocation'.
interface WorkerLocation {
          ~~~~~~~~~~~~~~
    at asset:///lib.webworker.d.ts:5488:11

    'WorkerLocation' was also declared here.
    declare class WorkerLocation {
                  ~~~~~~~~~~~~~~
        at asset:///lib.deno.worker.d.ts:75:15

TS2300 [ERROR]: Duplicate identifier 'WorkerLocation'.
declare var WorkerLocation: {
            ~~~~~~~~~~~~~~
    at asset:///lib.webworker.d.ts:5501:13

    'WorkerLocation' was also declared here.
    declare class WorkerLocation {
                  ~~~~~~~~~~~~~~
        at asset:///lib.deno.worker.d.ts:75:15

TS2300 [ERROR]: Duplicate identifier 'close'.
declare function close(): void;
                 ~~~~~
    at asset:///lib.webworker.d.ts:5905:18

    'close' was also declared here.
    declare var close: () => void;
                ~~~~~
        at asset:///lib.deno.worker.d.ts:66:13

TS2300 [ERROR]: Duplicate identifier 'postMessage'.
declare function postMessage(message: any, transfer: Transferable[]): void;
                 ~~~~~~~~~~~
    at asset:///lib.webworker.d.ts:5909:18

    'postMessage' was also declared here.
    declare var postMessage: (message: any) => void;
                ~~~~~~~~~~~
        at asset:///lib.deno.worker.d.ts:68:13

TS2300 [ERROR]: Duplicate identifier 'postMessage'.
declare function postMessage(message: any, options?: PostMessageOptions): void;
                 ~~~~~~~~~~~
    at asset:///lib.webworker.d.ts:5910:18

    'postMessage' was also declared here.
    declare var postMessage: (message: any) => void;
                ~~~~~~~~~~~
        at asset:///lib.deno.worker.d.ts:68:13

TS2300 [ERROR]: Duplicate identifier 'BinaryType'.
type BinaryType = "arraybuffer" | "blob";
     ~~~~~~~~~~
    at asset:///lib.webworker.d.ts:6002:6

    'BinaryType' was also declared here.
    type BinaryType = "arraybuffer" | "blob";
         ~~~~~~~~~~
        at asset:///lib.deno.websocket.d.ts:112:6

TS2300 [ERROR]: Duplicate identifier 'WorkerGlobalScope'.
declare class WorkerGlobalScope {
              ~~~~~~~~~~~~~~~~~
    at asset:///lib.deno.worker.d.ts:9:15

    'WorkerGlobalScope' was also declared here.
    interface WorkerGlobalScope extends EventTarget, WindowOrWorkerGlobalScope {
              ~~~~~~~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:5456:11    and here.
    declare var WorkerGlobalScope: {
                ~~~~~~~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:5482:13

TS2300 [ERROR]: Duplicate identifier 'DedicatedWorkerGlobalScope'.
declare class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
              ~~~~~~~~~~~~~~~~~~~~~~~~~~
    at asset:///lib.deno.worker.d.ts:42:15

    'DedicatedWorkerGlobalScope' was also declared here.
    interface DedicatedWorkerGlobalScope extends WorkerGlobalScope, AnimationFrameProvider {
              ~~~~~~~~~~~~~~~~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:1304:11    and here.
    declare var DedicatedWorkerGlobalScope: {
                ~~~~~~~~~~~~~~~~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:1326:13

TS2403 [ERROR]: Subsequent variable declarations must have the same type.  Variable 'onmessage' must be of type '((this: DedicatedWorkerGlobalScope, ev: MessageEvent<any>) => any) | null', but here has type '((this: WorkerGlobalScope & typeof globalThis, ev: MessageEvent<any>) => any) | null'.
declare var onmessage:
            ~~~~~~~~~
    at asset:///lib.deno.worker.d.ts:48:13

    'onmessage' was also declared here.
    declare var onmessage: ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any) | null;
                ~~~~~~~~~
        at asset:///lib.webworker.d.ts:5900:13

TS2403 [ERROR]: Subsequent variable declarations must have the same type.  Variable 'onmessageerror' must be of type '((this: DedicatedWorkerGlobalScope, ev: MessageEvent<any>) => any) | null', but here has type '((this: WorkerGlobalScope & typeof globalThis, ev: MessageEvent<any>) => any) | null'.
declare var onmessageerror:
            ~~~~~~~~~~~~~~
    at asset:///lib.deno.worker.d.ts:54:13

    'onmessageerror' was also declared here.
    declare var onmessageerror: ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any) | null;
                ~~~~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:5901:13

TS2403 [ERROR]: Subsequent variable declarations must have the same type.  Variable 'onerror' must be of type '((this: DedicatedWorkerGlobalScope, ev: ErrorEvent) => any) | null', but here has type '((this: WorkerGlobalScope & typeof globalThis, ev: ErrorEvent) => any) | null'.
declare var onerror:
            ~~~~~~~
    at asset:///lib.deno.worker.d.ts:60:13

    'onerror' was also declared here.
    declare var onerror: ((this: DedicatedWorkerGlobalScope, ev: ErrorEvent) => any) | null;
                ~~~~~~~
        at asset:///lib.webworker.d.ts:5920:13

TS2300 [ERROR]: Duplicate identifier 'close'.
declare var close: () => void;
            ~~~~~
    at asset:///lib.deno.worker.d.ts:66:13

    'close' was also declared here.
    declare function close(): void;
                     ~~~~~
        at asset:///lib.webworker.d.ts:5905:18

TS2300 [ERROR]: Duplicate identifier 'postMessage'.
declare var postMessage: (message: any) => void;
            ~~~~~~~~~~~
    at asset:///lib.deno.worker.d.ts:68:13

    'postMessage' was also declared here.
    declare function postMessage(message: any, transfer: Transferable[]): void;
                     ~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:5909:18    and here.
    declare function postMessage(message: any, options?: PostMessageOptions): void;
                     ~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:5910:18

TS2300 [ERROR]: Duplicate identifier 'WorkerLocation'.
declare class WorkerLocation {
              ~~~~~~~~~~~~~~
    at asset:///lib.deno.worker.d.ts:75:15

    'WorkerLocation' was also declared here.
    interface WorkerLocation {
              ~~~~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:5488:11    and here.
    declare var WorkerLocation: {
                ~~~~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:5501:13

TS6200 [ERROR]: Definitions of the following identifiers conflict with those in another file: Global, Instance, Memory, Module, Table, ImportExportKind, TableKind, ValueType, ExportValue, Exports, ImportValue, ModuleImports, Imports, BufferSource, MessageEvent, ErrorEvent, Worker, PerformanceEntryList, Performance, PerformanceEntry, PerformanceMark, PerformanceMeasure, CustomEvent
declare namespace WebAssembly {
~~~~~~~
    at asset:///lib.deno.shared_globals.d.ts:13:1

    Conflicts are in this file.
    interface AddEventListenerOptions extends EventListenerOptions {
    ~~~~~~~~~
        at asset:///lib.webworker.d.ts:25:1

TS2375 [ERROR]: Duplicate number index signature.
  [index: number]: string;
  ~~~~~~~~~~~~~~~~~~~~~~~~
    at asset:///lib.deno.shared_globals.d.ts:388:3

TS6200 [ERROR]: Definitions of the following identifiers conflict with those in another file: ReadableStreamReader, CountQueuingStrategy, ByteLengthQueuingStrategy, BlobPart, Blob, File, FormDataEntryValue, FormData, HeadersInit, Headers, RequestInfo, RequestCache, RequestCredentials, RequestMode, RequestRedirect, ReferrerPolicy, BodyInit, RequestDestination, Request, ResponseType, Response
interface DomIterable<K, V> {
~~~~~~~~~
    at asset:///lib.deno.fetch.d.ts:8:1

    Conflicts are in this file.
    interface AddEventListenerOptions extends EventListenerOptions {
    ~~~~~~~~~
        at asset:///lib.webworker.d.ts:25:1

TS2403 [ERROR]: Subsequent variable declarations must have the same type.  Variable 'ReadableStreamDefaultReader' must be of type '{ new <R = any>(stream: ReadableStream<R>): ReadableStreamDefaultReader<R>; prototype: ReadableStreamDefaultReader<any>; }', but here has type '{ new <R>(stream: ReadableStream<R>): ReadableStreamDefaultReader<R>; prototype: ReadableStreamDefaultReader<any>; }'.
declare var ReadableStreamDefaultReader: {
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at asset:///lib.deno.fetch.d.ts:40:13

    'ReadableStreamDefaultReader' was also declared here.
    declare var ReadableStreamDefaultReader: {
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:2777:13

TS2314 [ERROR]: Generic type 'ReadableStreamReader' requires 1 type argument(s).
  prototype: ReadableStreamReader;
             ~~~~~~~~~~~~~~~~~~~~
    at asset:///lib.deno.fetch.d.ts:52:14

TS2314 [ERROR]: Generic type 'ReadableStreamReader' requires 1 type argument(s).
  new (): ReadableStreamReader;
          ~~~~~~~~~~~~~~~~~~~~
    at asset:///lib.deno.fetch.d.ts:53:11

TS2403 [ERROR]: Subsequent variable declarations must have the same type.  Variable 'ReadableStream' must be of type '{ new <R = any>(underlyingSource?: UnderlyingSource<R> | undefined, strategy?: QueuingStrategy<R> | undefined): ReadableStream<R>; prototype: ReadableStream<...>; }', but here has type '{ new (underlyingSource: UnderlyingByteSource, strategy?: { highWaterMark?: number | undefined; size?: undefined; } | undefined): ReadableStream<Uint8Array>; new <R = any>(underlyingSource?: UnderlyingSource<...> | undefined, strategy?: QueuingStrategy<...> | undefined): ReadableStream<...>; prototype: ReadableStrea...'.
declare var ReadableStream: {
            ~~~~~~~~~~~~~~
    at asset:///lib.deno.fetch.d.ts:174:13

    'ReadableStream' was also declared here.
    declare var ReadableStream: {
                ~~~~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:2755:13

TS2717 [ERROR]: Subsequent property declarations must have the same type.  Property 'closed' must be of type 'Promise<undefined>', but here has type 'Promise<void>'.
  readonly closed: Promise<void>;
           ~~~~~~
    at asset:///lib.deno.fetch.d.ts:236:12

    'closed' was also declared here.
        readonly closed: Promise<undefined>;
                 ~~~~~~
        at asset:///lib.webworker.d.ts:5541:14

TS2717 [ERROR]: Subsequent property declarations must have the same type.  Property 'ready' must be of type 'Promise<undefined>', but here has type 'Promise<void>'.
  readonly ready: Promise<void>;
           ~~~~~
    at asset:///lib.deno.fetch.d.ts:238:12

    'ready' was also declared here.
        readonly ready: Promise<undefined>;
                 ~~~~~
        at asset:///lib.webworker.d.ts:5543:14

TS2403 [ERROR]: Subsequent variable declarations must have the same type.  Variable 'WritableStreamDefaultWriter' must be of type '{ new <W = any>(stream: WritableStream<W>): WritableStreamDefaultWriter<W>; prototype: WritableStreamDefaultWriter<any>; }', but here has type '{ new (): WritableStreamDefaultWriter<any>; prototype: WritableStreamDefaultWriter<any>; }'.
declare var WritableStreamDefaultWriter: {
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at asset:///lib.deno.fetch.d.ts:245:13

    'WritableStreamDefaultWriter' was also declared here.
    declare var WritableStreamDefaultWriter: {
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        at asset:///lib.webworker.d.ts:5550:13

TS2300 [ERROR]: Duplicate identifier 'CloseEvent'.
declare class CloseEvent extends Event {
              ~~~~~~~~~~
    at asset:///lib.deno.websocket.d.ts:14:15

    'CloseEvent' was also declared here.
    interface CloseEvent extends Event {
              ~~~~~~~~~~
        at asset:///lib.webworker.d.ts:965:11    and here.
    declare var CloseEvent: {
                ~~~~~~~~~~
        at asset:///lib.webworker.d.ts:980:13

TS2300 [ERROR]: Duplicate identifier 'WebSocket'.
declare class WebSocket extends EventTarget {
              ~~~~~~~~~
    at asset:///lib.deno.websocket.d.ts:38:15

    'WebSocket' was also declared here.
    interface WebSocket extends EventTarget {
              ~~~~~~~~~
        at asset:///lib.webworker.d.ts:5324:11    and here.
    declare var WebSocket: {
                ~~~~~~~~~
        at asset:///lib.webworker.d.ts:5375:13

TS2300 [ERROR]: Duplicate identifier 'BinaryType'.
type BinaryType = "arraybuffer" | "blob";
     ~~~~~~~~~~
    at asset:///lib.deno.websocket.d.ts:112:6

    'BinaryType' was also declared here.
    type BinaryType = "arraybuffer" | "blob";
         ~~~~~~~~~~
        at asset:///lib.webworker.d.ts:6002:6

TS2717 [ERROR]: Subsequent property declarations must have the same type.  Property 'subtle' must be of type 'SubtleCrypto', but here has type 'null'.
  readonly subtle: null;
           ~~~~~~
    at asset:///lib.deno.crypto.d.ts:9:12

    'subtle' was also declared here.
        readonly subtle: SubtleCrypto;
                 ~~~~~~
        at asset:///lib.webworker.d.ts:1007:14

TS6200 [ERROR]: Definitions of the following identifiers conflict with those in another file: DOMException, Event, EventTarget, EventListenerOrEventListenerObject, ProgressEvent, TextDecoder, TextEncoder, AbortController, URLSearchParams, URL
declare class DOMException extends Error {
~~~~~~~
    at asset:///lib.deno.web.d.ts:8:1

    Conflicts are in this file.
    interface AddEventListenerOptions extends EventListenerOptions {
    ~~~~~~~~~
        at asset:///lib.webworker.d.ts:25:1

Found 41 errors.
error: Uncaught (in promise) Error: Unhandled error event reached main worker.
    at Worker.#poll (deno:runtime/js/11_workers.js:269:21)
@kitsonk kitsonk added feat new feature (which has been agreed to/accepted) lsp related to the language server labels Mar 5, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Mar 5, 2021

Related to #8219 and others.

We need workspace folders and a config flag that indicates that files are worker scripts.

@Mesteery
Copy link

What about DOMException, Event, EventTarget, EventListenerOrEventListenerObject, ProgressEvent, TextDecoder, TextEncoder, TextDecoderStream, TextEncoderStream, AbortController, BlobPart, Blob, File, ReadableStreamReader, CountQueuingStrategy, ByteLengthQueuingStrategy, .... which do not depend on workers?

@kitsonk
Copy link
Contributor

kitsonk commented Aug 21, 2021

@Mesteery those currently work. If you have issues with them being available it is not related to this feature request. I would open a new issue in vscode_deno with reproduction information.

@Mesteery
Copy link

Yes they work but not when accessed from globalThis: globalThis.ByteLengthQueuingStrategy, for example, raises a error :

error: TS2339 [ERROR]: Property 'ByteLengthQueuingStrategy' does not exist on type 'typeof globalThis'.
globalThis.ByteLengthQueuingStrategy

@eight04
Copy link

eight04 commented Oct 9, 2023

Is there a workaround to this?

@NewYanko
Copy link

NewYanko commented Oct 9, 2023

Is there a workaround to this?

Also wondering. Is there a way to flag a file as being a worker?

@mahdiyari
Copy link

Similar

Property 'onmessage' does not exist on type 'Window & typeof globalThis'.deno-ts(2339)

@mommysgoodpuppy
Copy link

Is there a workaround to this?

My workaround is to do this.
const worker = self as unknown as Worker;

@mahdiyari
Copy link

You could ignore the line

// @ts-ignore: lack of types in deno
self.onmessage = (e: MessageEvent) => {}

@HuakunShen
Copy link

/// <reference lib="webworker" /> resolves the error locally, but will prevent jsr publish.
Error thrown during jsr publish
https://jsr.io/docs/troubleshooting#bannedtripleslashdirectives

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat new feature (which has been agreed to/accepted) lsp related to the language server
Projects
None yet
Development

No branches or pull requests

8 participants