How to extend type of globalThis
mickaelchanrion opened this issue ยท 2 comments
mickaelchanrion commented
Hello ๐,
This is not a bug, just a question.
In my current project, I use external script that will be assigned to property in window.
Example: dataLayer, Alpine
Since I'm using typescript, it won't allow me to use or assign unknown properties to globalThis
. How can I extend its type?
Many thanks.
zanminkian commented
Add a shims.d.ts
file in your project:
declare var foo: object
Then other files can write:
globalThis.foo = {}
This is not issues belong to this library. You should file your question in stackoverflow.
mickaelchanrion commented
Thanks.
What worked for my case:
import type Alpine from 'alpinejs'
declare global {
var Alpine: Alpine | undefined
}