0
0
Typescriptprogramming~5 mins

Namespace merging in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is namespace merging in TypeScript?
Namespace merging is when two or more namespaces with the same name combine their contents into a single namespace. This allows you to split code into parts but use it as one.
Click to reveal answer
intermediate
Can interfaces and namespaces merge in TypeScript?
Yes! Interfaces and namespaces with the same name can merge. The namespace can add static members or helper functions to the interface.
Click to reveal answer
intermediate
What happens if two namespaces with the same name have conflicting members?
If two namespaces have members with the same name and type, they merge fine. But if types conflict, TypeScript will show an error.
Click to reveal answer
beginner
Show a simple example of namespace merging in TypeScript.
Example:

namespace MySpace {
  export const a = 1;
}

namespace MySpace {
  export const b = 2;
}

// Now MySpace has both 'a' and 'b' members.
Click to reveal answer
beginner
Why use namespace merging instead of one big namespace?
Namespace merging helps organize code by splitting it into smaller parts. It also allows adding new members later without changing the original namespace.
Click to reveal answer
What does namespace merging allow you to do in TypeScript?
AConvert namespaces into modules
BMerge classes and interfaces automatically
CPrevent namespaces from being extended
DCombine multiple namespaces with the same name into one
Can a namespace and a class with the same name merge in TypeScript?
AYes, they merge their members
BNo, classes and namespaces cannot merge
COnly if the class is empty
DOnly if the namespace is empty
What happens if two merged namespaces have a member with the same name but different types?
ATypeScript throws an error
BThe first member is used, the second ignored
CThe second member overwrites the first
DThey merge without issues
Which of these can be merged with a namespace?
AFunctions
BVariables
CInterfaces
DNone of the above
Why might you use namespace merging?
ATo speed up program execution
BTo organize code into smaller parts
CTo prevent code reuse
DTo avoid using modules
Explain how namespace merging works in TypeScript and give a simple example.
Think about how two parts with the same name combine their contents.
You got /2 concepts.
    What are the benefits of using namespace merging instead of one large namespace?
    Consider how splitting helps keep code clean and flexible.
    You got /3 concepts.