• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

I Like Kill Nerds

The blog of Australian Front End / Aurelia Javascript Developer & brewing aficionado Dwayne Charrington // Aurelia.io Core Team member.

  • Home
  • Aurelia 2
  • Aurelia 1
  • About
  • Aurelia 2 Consulting/Freelance Work

How to Add Typings to the Global TypeScript Window Object

TypeScript · September 28, 2021

Does this error look familiar? Property ‘AddressFinder’ does not exist on type ‘Window & typeof globalThis’.ts(2339)

There will come a time in TypeScript when you are not dealing with package-managed dependencies from Npm. These will come in the form of scripts added into the head or footer of your application. Furthermore, these global scripts might not have typings.

You will also run into this error for numerous jQuery plugins and other libraries which work on the premise of modifying the global Window object.

In my instance, I was using the AddressFinder API which uses a provided script you embed into your application.

Adding in your own custom typings is a last resort. You should always check to see if there are officially provided typings for your package/script before proceeding to add in your own.

In older versions of TypeScript you could just throw in an interface called Window and it would automatically add in your typing values to the Window object — times have changed and now the Window interface lives under the global scope instead.

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

By specifying declare global you’re saying whatever interfaces you specifying inside will be part of the global scope. Simply create a Window interface and then declare your properties inside. I am being naughty and using any to get myself out of a pickle, but will sort out proper typings later.

Dwayne

Leave a Reply Cancel reply

0 Comments
Inline Feedbacks
View all comments

Primary Sidebar

Popular

  • The Quad Cortex Desktop Editor is Finally Announced
  • Thoughts on the Flipper Zero
  • NBN Box Installed Inside of Garage, Where Do You Put The Modem?
  • How To Install Eufy Security Cameras Without Drilling or Using Screws
  • Wild Natural Deodorant Review

Copyright © 2023 · Dwayne Charrington · Log in

wpDiscuz