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
问题-上面的行显示:
Error:(30, 36) TS2339: Property 'onWebsocketsMessageReceived' does not exist on type 'Window & typeof globalThis'.
为什么会这样?另外,尽管我无法确定确切的更改,但我确定整个过程在不久前就可以正常进行了。尽管如此,相关的(提供的)内容看起来确实可以正确编写。
tsconfig.json
:
{
"include": [
"src/**/*"
],
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"sourceMap": true,
"outDir": "./dist",
"strict": true,
"noImplicitAny": false,
"strictNullChecks": false,
}
}
答案 0 :(得分:1)
只需在您的Window
中声明root/global.d.ts
接口
declare interface Window {
onWebsocketsMessageReceived: (data: ArrayBuffer) => GGMessage | null
}
它将自动合并到lib.dom.d.ts
中的定义中。