0
0
Typescriptprogramming~5 mins

Global augmentation in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is global augmentation in TypeScript?
Global augmentation means adding new types or members to existing global types or modules, so they are available everywhere in your project.
Click to reveal answer
beginner
How do you declare a global augmentation in TypeScript?
You use the declare global block inside a module to add or extend global types or interfaces.
Click to reveal answer
intermediate
Why use global augmentation instead of creating new types?
Global augmentation lets you extend existing types without rewriting or duplicating them, making your code more consistent and easier to maintain.
Click to reveal answer
intermediate
What is the difference between module augmentation and global augmentation?
Module augmentation adds or changes types inside a specific module, while global augmentation changes types available everywhere in the project.
Click to reveal answer
beginner
Show a simple example of global augmentation adding a property to the Window interface.
export {}; declare global { interface Window { myCustomProperty: string; } } window.myCustomProperty = "Hello!"; console.log(window.myCustomProperty); // Outputs: Hello!
Click to reveal answer
Which keyword is used to start a global augmentation block in TypeScript?
Aglobal declare
Bdeclare global
Caugment global
Dmodule global
Global augmentation is useful for:
AImporting external modules
BCreating new unrelated types
CAdding new properties to existing global types
DChanging JavaScript runtime behavior
Where should you place a global augmentation in your TypeScript project?
AIn a CSS file
BIn a JavaScript file
CIn the main HTML file
DInside a module file with <code>export {}</code>
What happens if you forget to add export {} in a global augmentation file?
AThe file is treated as a script, and augmentation may not work correctly
BThe augmentation works perfectly
CTypeScript throws a syntax error
DThe file is ignored by the compiler
Which of these is a valid use of global augmentation?
AAdding a new method to the Array interface globally
BChanging the behavior of console.log
CAdding a new HTML tag
DModifying CSS styles
Explain how to add a new property to the Window interface globally in TypeScript.
Think about using 'declare global' and interface extension.
You got /4 concepts.
    Describe the difference between global augmentation and module augmentation in TypeScript.
    Consider where the types are available after augmentation.
    You got /4 concepts.