Extending global types (e.g. “Window”) inside a typescript module

Yes, you just need to wrap the interface into global declaration:

declare global {
    interface Window {
        myCounter: number;
    }
}

Global scope can be augmented from modules using a declare global declarations

More info here


** Make sure the file is treated as a module (has import or export statement, if not – you can add empty export {})

Leave a Comment