-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Document how to extend window #2662
Copy link
Copy link
Closed
Labels
add new contentDocument something that is not in docs. May require testing, confirmation, or affect other pages.Document something that is not in docs. May require testing, confirmation, or affect other pages.good first issueGood for newcomersGood for newcomers
Description
Sometimes, you want to add a property to the window interface. TypeScript doesn't really document how to do this properly, and this situation is more likely to arise in Astro since we support TypeScript directly in script tags.
The solution is to add to env.d.ts (or any other .d.ts that's in the project scope) a Window interface, like such:
interface Window {
helloChris: string;
}The property will then appear in completions and by type-checked with no issues:
Side note
A similar situation happens for globalThis, but the way to add property to it is completely different, as you need to do the following:
export {}
declare global {
function myFunction(): boolean;
var myVariable: number;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
add new contentDocument something that is not in docs. May require testing, confirmation, or affect other pages.Document something that is not in docs. May require testing, confirmation, or affect other pages.good first issueGood for newcomersGood for newcomers

