Skip to content

Improve PixiJS utilities type safety: replace unsafe any casts with proper type guards for renderer and event handling - #36

Merged
devfoma merged 7 commits into
Ender-Stellar:mainfrom
AugistineCreates:pixi-typing-fix
Jun 19, 2026
Merged

devfoma merged 7 commits into
Ender-Stellar:mainfrom
AugistineCreates:pixi-typing-fix

Conversation

@AugistineCreates

Copy link
Copy Markdown
Contributor

This pr closes #9

This pull request tightens TypeScript type safety in the PixiJS utility module (components/shared/pixi/utils.ts). The previous implementation used unsafe any casts and work‑arounds that effectively disabled type checking. The changes replace those casts with explicit type‑guard checks and proper typings, removing the need for @ts‑nocheck‑style suppression and preventing possible runtime crashes when upgrading or changing PixiJS canvas interfaces.

Key Changes

  • components/shared/pixi/utils.ts
    • Rewrote isDestroyed to safely detect a WebGLRenderer by checking for a gl property via a type‑guard (maybeGL) and handling WebGPURenderer correctly.
    • Updated the fallback logic for non‑WebGL renderers to assume the application is not destroyed.
    • Refactored waitUntilPixiIsReady to avoid casting to any; the canvas is cast to unknown then to EventTarget, and the listener resolves via an arrow function, preserving type safety.
  • No other files were modified.

Why This Matters

  • Eliminates any usage, reducing the risk of silent type errors, especially as PixiJS adds WebGPU support.
  • Improves maintainability by allowing developers to rely on accurate TypeScript diagnostics without needing @ts‑nocheck work‑arounds.
  • Prevents runtime crashes by checking for the existence of gl.isContextLost before invoking it.

Testing & Verification

  • Local TypeScript compilation (npm run build) succeeds with no type errors.
  • Manual testing of Pixi‑related components shows no regressions; the only changes are type‑safety improvements.

@devfoma
devfoma merged commit a4eba8e into Ender-Stellar:main Jun 19, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

frontend: Disabled Type Safety in PIXI Canvas Utilities

2 participants