TypeScript Quiz
Thirty questions covering the whole course. Choose an answer for each, then press Check answers at the bottom to see your score and an explanation for every question.
1. What happens to type annotations when TypeScript compiles to JavaScript?
Types are erased at compile time; the output is ordinary JavaScript (lesson 01).
2. Which declaration is inferred as the literal type "draft"?
A const can never change, so TypeScript keeps the exact literal type (lesson 04).
3. Which type accepts any value but forces you to narrow it before use?
unknown is the safe counterpart to any (lesson 05).
4. What is the return type of a function that always throws?
It can never produce a value, so its return type is never (lesson 05).
5. What does readonly string[] prevent?
Readonly arrays remove the methods that modify the array (lesson 06).
6. How do you write a tuple of a string followed by a number?
Tuples list one type per position in square brackets (lesson 07).
7. Which can an interface do that a type alias cannot?
Interfaces support declaration merging; duplicate type aliases are an error (lessons 09 and 34).
8. What does a string enum NOT generate that a numeric enum does?
Only numeric enums get reverse mappings like Status[1] === "Shipped" (lesson 10).
9. Given value: string | number, which call compiles without narrowing?
Only members shared by every type in the union are allowed (lesson 12).
10. What does 0 ?? 20 evaluate to?
?? only falls back for null or undefined, so 0 is kept (lesson 13).
11. What does a type assertion like value as number do at runtime?
Assertions are erased; use Number() for real conversion (lesson 14).
12. What does the satisfies operator do?
satisfies validates without widening (lesson 14).
13. In a set of function overloads, which signature can callers NOT use directly?
Only the overload signatures are visible; the implementation signature is hidden (lesson 16).
14. What does constructor(private name: string) {} do?
This is a parameter property (lesson 17).
15. Which access modifier lets subclasses — but not outside code — access a member?
protected members are visible to the class and its subclasses (lesson 18).
16. What is true of an abstract class?
Abstract classes are partial classes meant to be extended (lesson 18).
17. What does the T in function first<T>(items: T[]): T represent?
Generics take types as parameters, usually inferred from arguments (lesson 20).
18. What does K extends keyof T mean?
keyof T is a union of property names, and extends constrains K to it (lessons 21 and 24).
19. Which return type makes isCat(pet) narrow pet when it returns true?
A type predicate tells TypeScript what a true result means (lesson 23).
20. In an exhaustive switch, what type is the value in the default branch once every case is handled?
Assigning it to never makes a missing case a compile error (lesson 23).
21. What is (typeof ROLES)[number] when ROLES = ["admin", "user"] as const?
Indexing a readonly tuple type by number gives the union of its elements (lesson 24).
22. What does Record<"a" | "b", number> require?
With a union of literal keys, every key is required (lesson 25).
23. Which utility type removes listed properties from an object type?
Omit works on properties; Exclude works on union members (lessons 26–27).
24. What does Awaited<Promise<string>> produce?
Awaited unwraps promise types like await does (lesson 27).
25. In a mapped type, what does -? do?
A minus prefix removes a modifier; that's how Required works (lesson 28).
26. What is T extends string ? "yes" : "no" when T is string | number?
Conditional types distribute over unions when checking a bare type parameter (lesson 29).
27. Why use import type { User } from "./models"?
Type-only imports are always erased (lesson 31).
28. In strict mode, what is the type of err in catch (err)?
Anything can be thrown, so you must narrow it first (lesson 37).
29. Since TypeScript 6.0, what must you do for process from @types/node to be recognised?
The types option now defaults to an empty list (lessons 33 and 38).
30. What is the main change in TypeScript 7.0?
TypeScript 7 is a native port of the compiler; the language itself is unchanged (lesson 44).
Missed a few? Each explanation names the lesson to revisit. When you're ready, try the exercises for hands-on practice.