Recall & Review
beginner
What is module augmentation in TypeScript?
Module augmentation is a way to add new members or modify existing ones in an already declared module without changing the original source code.
Click to reveal answer
beginner
How do you start a module augmentation block in TypeScript?
You use the
declare module 'module-name' syntax to open a block where you can add or change module contents.Click to reveal answer
intermediate
Can you augment a module by adding new functions? Give an example.
Yes. For example, to add a new function <code>newFunc</code> to module <code>myModule</code>:
<pre>declare module 'myModule' {
export function newFunc(): void;
}</pre>Click to reveal answer
intermediate
What happens if you augment a module with a conflicting type or member?
TypeScript will merge compatible declarations, but if there is a conflict (like different types for the same member), it will cause a type error.
Click to reveal answer
beginner
Why use module augmentation instead of editing the original module?
Because the original module might be from a library or external source you can't or shouldn't change. Augmentation lets you safely extend it.
Click to reveal answer
Which keyword starts a module augmentation block in TypeScript?
✗ Incorrect
You start with
declare module 'module-name' to augment a module.What is the main purpose of module augmentation?
✗ Incorrect
Module augmentation lets you add or change members in an existing module.
If you add a new function in module augmentation, what must you do?
✗ Incorrect
You declare the function signature in augmentation; implementation is elsewhere.
What happens if two augmentations declare the same member with different types?
✗ Incorrect
Conflicting types cause a type error in TypeScript.
Which scenario is best suited for module augmentation?
✗ Incorrect
Module augmentation is ideal for safely extending third-party libraries.
Explain how to use module augmentation syntax to add a new function to an existing module.
Think about how you tell TypeScript about new parts without changing original code.
You got /3 concepts.
Describe what happens when conflicting types are declared in module augmentation and how to avoid it.
Conflicts cause errors; be careful to match or extend types properly.
You got /3 concepts.