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?

2. Which declaration is inferred as the literal type "draft"?

3. Which type accepts any value but forces you to narrow it before use?

4. What is the return type of a function that always throws?

5. What does readonly string[] prevent?

6. How do you write a tuple of a string followed by a number?

7. Which can an interface do that a type alias cannot?

8. What does a string enum NOT generate that a numeric enum does?

9. Given value: string | number, which call compiles without narrowing?

10. What does 0 ?? 20 evaluate to?

11. What does a type assertion like value as number do at runtime?

12. What does the satisfies operator do?

13. In a set of function overloads, which signature can callers NOT use directly?

14. What does constructor(private name: string) {} do?

15. Which access modifier lets subclasses — but not outside code — access a member?

16. What is true of an abstract class?

17. What does the T in function first<T>(items: T[]): T represent?

18. What does K extends keyof T mean?

19. Which return type makes isCat(pet) narrow pet when it returns true?

20. In an exhaustive switch, what type is the value in the default branch once every case is handled?

21. What is (typeof ROLES)[number] when ROLES = ["admin", "user"] as const?

22. What does Record<"a" | "b", number> require?

23. Which utility type removes listed properties from an object type?

24. What does Awaited<Promise<string>> produce?

25. In a mapped type, what does -? do?

26. What is T extends string ? "yes" : "no" when T is string | number?

27. Why use import type { User } from "./models"?

28. In strict mode, what is the type of err in catch (err)?

29. Since TypeScript 6.0, what must you do for process from @types/node to be recognised?

30. What is the main change in TypeScript 7.0?

Missed a few? Each explanation names the lesson to revisit. When you're ready, try the exercises for hands-on practice.