Recall & Review
beginner
What is type erasure in TypeScript?
Type erasure means that TypeScript removes all type information when it compiles code to JavaScript. The types exist only during development and are not present at runtime.
Click to reveal answer
beginner
Why does TypeScript use type erasure?
TypeScript uses type erasure to keep the output JavaScript clean and compatible with all JavaScript environments, which do not support types natively.
Click to reveal answer
intermediate
What is a common consequence of type erasure when using generics in TypeScript?
Since types are erased, you cannot check or enforce generic types at runtime. For example, you can't check if a value matches a generic type parameter inside the compiled JavaScript.
Click to reveal answer
intermediate
How does type erasure affect debugging TypeScript code?
Because types are removed, debugging happens on plain JavaScript code. This means you can't see TypeScript types in runtime errors or logs, only JavaScript values.
Click to reveal answer
intermediate
Can you use type information at runtime in TypeScript? Why or why not?
No, you cannot use type information at runtime because TypeScript removes all types during compilation. To use type-like checks at runtime, you must write explicit JavaScript code or use libraries.
Click to reveal answer
What happens to TypeScript types after compilation?
✗ Incorrect
TypeScript removes all types during compilation, so the output JavaScript has no type information.
Why can't you check generic types at runtime in TypeScript?
✗ Incorrect
Generics exist only during compilation and are erased, so runtime checks are not possible.
Which of these is a consequence of type erasure?
✗ Incorrect
Since types are erased, you cannot use them at runtime.
How can you perform type-like checks at runtime in TypeScript?
✗ Incorrect
TypeScript types are erased, so runtime checks must be done manually or with helper libraries.
What does type erasure help TypeScript achieve?
✗ Incorrect
Removing types ensures the output runs anywhere JavaScript runs.
Explain what type erasure is and why TypeScript uses it.
Think about what happens to types when TypeScript turns into JavaScript.
You got /3 concepts.
Describe one consequence of type erasure when working with generics in TypeScript.
Consider what you cannot do with generic types after compilation.
You got /3 concepts.