DevAcademy
PracticeTypeScriptIntermediate

TypeScript Intermediate Practice

27 questions covering 9 TypeScript topics.

Quick Quiz

1. What is an index signature used for?

2. What does Record<string, number> describe?

3. When does TypeScript perform excess property checks?

4. What type does an optional property implicitly include?

5. What happens if you try to reassign a readonly property after creation?

6. Does readonly provide true runtime immutability like Object.freeze()?

7. Does a type assertion convert a value at runtime?

8. What does the trailing ! (non-null assertion) tell the compiler?

9. What happens if a type assertion turns out to be wrong?

10. What does the parameter property shorthand (constructor(public name: string)) do?

11. What must a subclass constructor call before using this, if the parent has its own constructor?

12. Can an abstract class be instantiated directly with new?

13. Which access modifier is the default when none is specified?

14. Can a protected member be accessed from a subclass?

15. What is the key difference between TypeScript’s private and native # private fields?

16. Which feature is unique to interface and not available with type?

17. Can a type alias represent a union like string | number?

18. What happens if you declare two interfaces with the same name?

19. What problem do generics solve?

20. In function firstElement<T>(arr: T[]): T, how is T determined?

21. Can interfaces and classes be generic, not just functions?

22. Why does an unconstrained generic <T> not allow accessing value.length?

23. What does <T extends HasLength> do?

24. What does K extends keyof T typically guarantee in a function signature?

25. What does narrowing mean in TypeScript?

26. Which operator narrows a union based on whether an object has a specific property?

27. What makes a discriminated union safe and exhaustive to narrow?