TypeScript · Middle · Question 40 of 75
How do you extend the type of the global Window object from a module?
export {};
declare global {
interface Window { dataLayer: unknown[] }
}- ✓Correct answer: With
declare globaland merging into theWindowinterface - 2With
window.dataLayer = []- the type is inferred automatically - 3With
type Window = Window & { dataLayer: unknown[] }
Explanation
In a module file (with import/export), global declarations go inside declare global. The Window interface merges with your extension. Redeclaring type Window causes a duplicate identifier error.