• 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

  • Testing Event Listeners In Jest (Without Using A Library)
  • How To Get The Hash of A File In Node.js
  • How To Mock uuid In Jest
  • Which Neural DSP Archetype Plugins Should You Buy?
  • How to Copy Files Using the Copy Webpack Plugin (without copying the entire folder structure)
  • Removing A Character From The Start/End of a String In Javascript
  • How To Convert FormData To JSON Object
  • How To Correctly Use Semantic HTML5 <article>, <main> and <section> Tags
  • Wild Natural Deodorant Review
  • How To Get Last 4 Digits of A Credit Card Number in Javascript

Recent Comments

  • Thebe on How to Remove the My Sites Menu From the WordPress Admin Bar
  • Maccas worker jn the 2000s on Dear McDonald’s: bring back the Warm Cookie Sundae, you cowards
  • Anamika Singh on Testing Event Listeners In Jest (Without Using A Library)
  • Stefan on A List of WordPress Gutenberg Core Blocks
  • pandammonium on A List of WordPress Gutenberg Core Blocks

Copyright © 2022 · Dwayne Charrington · Log in

wpDiscuz