1

root/global.d.ts:

import {GGMessage} from "./GGMessage";
export {}

declare global {
    export interface Window {onWebsocketsMessageReceived: (data: ArrayBuffer) => GGMessage | null}
}

root/src/webSocketProxy.ts:

window.onWebsocketsMessageReceived

PROBLEM - The line above yields:

Error:(30, 36) TS2339: Property 'onWebsocketsMessageReceived' does not exist on type 'Window & typeof globalThis'.

Why is that so? Also, I am pretty sure the entire thing worked just a while ago, though I'm unable to determine the exact changes. Nevertheless, the relevant (provided) things do look to be written properly.

tsconfig.json:

{
  "include": [
    "src/**/*"
  ],
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
     "sourceMap": true,
     "outDir": "./dist",
    "strict": true,
     "noImplicitAny": false,
    "strictNullChecks": false,
  }
}
2
  • try to declare the window stuff on a script file at the start of your program, not in a d.ts file. It did the trick for me. Commented Nov 19, 2019 at 7:47
  • It has probably something to do with some breaking changes introduced in TypeScript 3.5: devblogs.microsoft.com/typescript/announcing-typescript-3-5/…. Did you upgrade from an older version recently? Commented Nov 19, 2019 at 8:33

1 Answer 1

5

Just declare the Window interface in your root/global.d.ts

declare interface Window {
 onWebsocketsMessageReceived: (data: ArrayBuffer) => GGMessage | null
}

it will be auto merged into the definition in lib.dom.d.ts.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.