javascripttypescripterror-handlingglobal-variablespixi.js

TypeScript Error TS7017: Implicit any type for custom globalThis property in Pixi.js application


I'm working on a Pixi.js application where I need to store the application instance globally using globalThis. I've extended the Window interface to include a custom property PIXI_APP. However, when I try to assign the application instance to globalThis.PIXI_APP, I encounter the TypeScript error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.

I extended the Window interface in a declare global block and tried assigning the application instance to globalThis.PIXI_APP. Despite this, TypeScript does not recognize the property on globalThis, leading to the mentioned error.

declare global {
    interface Window {
        __PIXI_APP__: any;
    }
}

globalThis.__PIXI_APP__ = application;

Solution

  • Fixed this common issue while using PixiJS Devtools.

    Tried like below and working fine at my end.

    declare global {
        interface GlobalThis {
            __PIXI_APP__: any;
        }
    }
    
    export {};
    
    (globalThis as any).__PIXI_APP__ = application;