Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

refactor: replace window as any with typed Window interface globals

esenginea6aa3bfc4911
diff --git a/desktop/src/globals.d.ts b/desktop/src/globals.d.ts
new file mode 100644
index 000000000..a714ecc9c
--- /dev/null
+++ b/desktop/src/globals.d.ts
@@ -0,0 +1,7 @@
+import type { ESEngineModule } from 'esengine';
+
+declare global {
+ interface Window {
+ __ESEngineModule?: (config?: unknown) => Promise<ESEngineModule>;
+ }
+}
diff --git a/desktop/src/main.ts b/desktop/src/main.ts
index a16d3e179..d210f008c 100644
--- a/desktop/src/main.ts
+++ b/desktop/src/main.ts
@@ -34,7 +34,7 @@ async function loadWasmModule(): Promise<ESEngineModule | null> {
await loadScript('/wasm/esengine.js');
await new Promise<void>((resolve, reject) => {
- if ((window as any).__ESEngineModule) {
+ if (window.__ESEngineModule) {
resolve();
return;
}
@@ -49,7 +49,7 @@ async function loadWasmModule(): Promise<ESEngineModule | null> {
}, { once: true });
});
- const createModule = (window as any).__ESEngineModule;
+ const createModule = window.__ESEngineModule;
if (typeof createModule !== 'function') {
console.warn('WebGL preview disabled: ESEngineModule not available');
return null;
diff --git a/editor/src/io/SceneSerializer.ts b/editor/src/io/SceneSerializer.ts
index c2b476d58..bd580d222 100644
--- a/editor/src/io/SceneSerializer.ts
+++ b/editor/src/io/SceneSerializer.ts
@@ -191,7 +191,7 @@ async function browserSaveFile(json: string, name: string): Promise<string | nul
if ('showSaveFilePicker' in window) {
try {
- const handle = await (window as any).showSaveFilePicker({
+ const handle = await window.showSaveFilePicker!({
suggestedName: name,
types: [{
description: 'ESEngine Scene',
diff --git a/sdk/.gitignore b/sdk/.gitignore
index 008f9b555..a653f321c 100644
--- a/sdk/.gitignore
+++ b/sdk/.gitignore
@@ -8,6 +8,7 @@ dist/
src/**/*.js
src/**/*.js.map
src/**/*.d.ts
+!src/globals.d.ts
# Example build outputs (keep esengine.js and wasm for demo)
examples/**/*.js
diff --git a/sdk/src/component.ts b/sdk/src/component.ts
index fdcecf278..ef9994f67 100644
--- a/sdk/src/component.ts
+++ b/sdk/src/component.ts
@@ -55,8 +55,8 @@ function registerToEditor(
defaults: Record<string, unknown>,
isTag: boolean
): void {
- if (typeof window !== 'undefined' && (window as any).__esengine_registerComponent) {
- (window as any).__esengine_registerComponent(name, defaults, isTag);
+ if (typeof window !== 'undefined' && window.__esengine_registerComponent) {
+ window.__esengine_registerComponent(name, defaults, isTag);
}
}
diff --git a/sdk/src/globals.d.ts b/sdk/src/globals.d.ts
new file mode 100644
index 000000000..3c7139a91
--- /dev/null
+++ b/sdk/src/globals.d.ts
@@ -0,0 +1,4 @@
+interface Window {
+ __esengine_registerComponent?: (name: string, defaults: Record<string, unknown>, isTag: boolean) => void;
+ __esengine_spineEvent?: (entity: number, eventData: unknown) => void;
+}
diff --git a/sdk/src/spine.ts b/sdk/src/spine.ts
index f7e631fa5..718c3ad9a 100644
--- a/sdk/src/spine.ts
+++ b/sdk/src/spine.ts
@@ -318,7 +318,7 @@ export class SpineController {
private setupEventBridge(): void {
if (typeof window !== 'undefined') {
- (window as any).__esengine_spineEvent = (entity: Entity, eventData: any) => {
+ window.__esengine_spineEvent = (entity: Entity, eventData: any) => {
this.dispatchEvent(entity, eventData);
};
}