Skip to content
🔷

TypeScript Basics

150 exercises

Practice exercises for typescript basics.

  1. 1

    Primitive Types Quiz

    Test your knowledge of TypeScript primitive types and identify which is not primitive.

    Multiple Choice Easy
  2. 2

    Type Annotation Syntax

    Identify the correct syntax for a type annotation on a variable in TypeScript.

    Multiple Choice Easy
  3. 3

    Interface vs Type Alias

    Understand the key difference between interface and type alias for object shapes.

    Multiple Choice Medium
  4. 4

    Union Types Quiz

    Test your understanding of union types and how they combine multiple possible types.

    Multiple Choice Easy
  5. 5

    Intersection Types Quiz

    Understand intersection types and how they combine multiple types into one.

    Multiple Choice Medium
  6. 6

    Enum Basics Quiz

    Test your knowledge of TypeScript enums and their default numeric values.

    Multiple Choice Easy
  7. 7

    Generics Basics Quiz

    Understand the purpose of generics and why they are used in TypeScript.

    Multiple Choice Medium
  8. 8

    Type Guards Quiz

    Test your understanding of type guards and how they narrow types at runtime.

    Multiple Choice Medium
  9. 9

    Optional Chaining Quiz

    Understand how optional chaining (?.) works with null and undefined values.

    Multiple Choice Easy
  10. 10

    Nullish Coalescing Quiz

    Test your knowledge of the nullish coalescing operator (??) and how it differs from ||.

    Multiple Choice Easy
  11. 11

    Partial Utility Type Quiz

    Understand what the Partial<T> utility type does to an existing type.

    Multiple Choice Medium
  12. 12

    Readonly Arrays Quiz

    Test your understanding of readonly arrays and what operations are prevented.

    Multiple Choice Medium
  13. 13

    Tuple Types Quiz

    Understand tuple types and how they differ from regular arrays.

    Multiple Choice Medium
  14. 14

    Function Type Quiz

    Test your knowledge of function type signatures in TypeScript.

    Multiple Choice Easy
  15. 15

    Void vs Undefined Quiz

    Understand the difference between void and undefined return types.

    Multiple Choice Medium
  16. 16

    Never Type Quiz

    Test your understanding of the never type and when it occurs.

    Multiple Choice Medium
  17. 17

    Unknown vs Any Quiz

    Understand the difference between unknown and any types in TypeScript.

    Multiple Choice Medium
  18. 18

    Type Assertion Quiz

    Test your knowledge of type assertions and their syntax in TypeScript.

    Multiple Choice Easy
  19. 19

    Strict Mode Quiz

    Understand what the strict flag in tsconfig.json enables.

    Multiple Choice Medium
  20. 20

    Type Inference Quiz

    Test your understanding of how TypeScript infers types without explicit annotations.

    Multiple Choice Easy
  21. 21

    Predict Type Annotation Output

    Predict the console output of a TypeScript program with type annotations.

    Predict Output Beginner
  22. 22

    Predict Union Narrowing Output

    Predict the output when narrowing a union type with typeof.

    Predict Output Easy
  23. 23

    Predict Tuple Access Output

    Predict the output when accessing elements of a typed tuple.

    Predict Output Easy
  24. 24

    Predict Enum Value Output

    Predict the numeric output of a TypeScript enum.

    Predict Output Easy
  25. 25

    Predict Optional Chaining Output

    Predict the output when using optional chaining with a null object.

    Predict Output Easy
  26. 26

    Predict Nullish Coalescing Output

    Predict the output of the nullish coalescing operator with various values.

    Predict Output Easy
  27. 27

    Predict Type Guard Output

    Predict the output when using a user-defined type guard to narrow a type.

    Predict Output Medium
  28. 28

    Predict Keyof Output

    Predict the output when using keyof to extract object keys.

    Predict Output Medium
  29. 29

    Predict typeof Guard Output

    Predict the output when using typeof for type narrowing in a function.

    Predict Output Easy
  30. 30

    Predict instanceof Output

    Predict the output when using instanceof for class-based type narrowing.

    Predict Output Medium
  31. 31

    Predict Mapped Type Output

    Predict the output when using a mapped type to transform object properties.

    Predict Output Medium
  32. 32

    Predict Conditional Type Output

    Predict the output when a conditional type resolves at compile time.

    Predict Output Medium
  33. 33

    Predict Function Return Output

    Predict the output of a TypeScript function with explicit return types.

    Predict Output Easy
  34. 34

    Predict Generic Inference Output

    Predict the output when TypeScript infers generic type parameters.

    Predict Output Medium
  35. 35

    Predict Const Assertion Output

    Predict the output when using const assertion for literal type inference.

    Predict Output Medium
  36. 36

    Predict Satisfies Operator Output

    Predict the output when using the satisfies operator to check a type.

    Predict Output Medium
  37. 37

    Predict Template Literal Output

    Predict the output when using template literal types.

    Predict Output Medium
  38. 38

    Predict Indexed Access Output

    Predict the output when using indexed access types to extract a property type.

    Predict Output Medium
  39. 39

    Predict Pick Utility Output

    Predict the output when using the Pick utility type to select properties.

    Predict Output Medium
  40. 40

    Predict Switch Narrowing Output

    Predict the output when using a switch statement for type narrowing with discriminated unions.

    Predict Output Medium
  41. 41

    Fill: Type Annotation

    Complete the type annotation for a variable that stores a number.

    Fill in the Blank Beginner
  42. 42

    Fill: Interface Property

    Complete an interface property declaration with the correct type.

    Fill in the Blank Easy
  43. 43

    Fill: Generic Function

    Complete a generic function declaration with the type parameter.

    Fill in the Blank Medium
  44. 44

    Fill: Type Alias

    Complete a type alias declaration for a union of string literals.

    Fill in the Blank Easy
  45. 45

    Fill: Union Type

    Complete a union type annotation using the pipe operator.

    Fill in the Blank Easy
  46. 46

    Fill: Tuple Type

    Complete a tuple type declaration with the correct syntax.

    Fill in the Blank Medium
  47. 47

    Fill: Enum Member

    Complete an enum declaration with a string value.

    Fill in the Blank Easy
  48. 48

    Fill: Type Guard

    Complete a user-defined type guard with the correct return type predicate.

    Fill in the Blank Medium
  49. 49

    Fill: Utility Type

    Complete a utility type that makes all properties optional.

    Fill in the Blank Medium
  50. 50

    Fill: Mapped Type

    Complete a mapped type that converts all properties to readonly.

    Fill in the Blank Medium
  51. 51

    Fill: Conditional Type

    Complete a conditional type that checks if T extends string.

    Fill in the Blank Medium
  52. 52

    Fill: Keyof Operator

    Complete a type that extracts all keys from an object type.

    Fill in the Blank Medium
  53. 53

    Fill: typeof Guard

    Complete a typeof type guard for narrowing a string.

    Fill in the Blank Easy
  54. 54

    Fill: instanceof Guard

    Complete an instanceof type guard for narrowing to a class type.

    Fill in the Blank Easy
  55. 55

    Fill: Type Assertion

    Complete a type assertion using the as keyword.

    Fill in the Blank Easy
  56. 56

    Fill: Satisfies Operator

    Complete a type check using the satisfies operator.

    Fill in the Blank Medium
  57. 57

    Fill: Const Assertion

    Complete a const assertion to get literal types.

    Fill in the Blank Medium
  58. 58

    Fill: Optional Property

    Complete an interface with an optional property.

    Fill in the Blank Easy
  59. 59

    Fill: Readonly Modifier

    Complete a readonly array type declaration.

    Fill in the Blank Easy
  60. 60

    Fill: Function Type

    Complete a function type signature.

    Fill in the Blank Easy
  61. 61

    Find: Type Mismatch

    Find the type error in a variable assignment.

    Find the Mistake Easy
  62. 62

    Find: Missing Return Type

    Find the error in a function that doesn't match its declared return type.

    Find the Mistake Easy
  63. 63

    Find: Wrong Generic Constraint

    Find the error in a generic function with an incorrect type constraint.

    Find the Mistake Medium
  64. 64

    Find: Incorrect Type Assertion

    Find the error in an unsafe type assertion.

    Find the Mistake Medium
  65. 65

    Find: Missing Type Guard

    Find the error where a type guard is needed but missing.

    Find the Mistake Medium
  66. 66

    Find: Wrong Union Type

    Find the error in a union type usage.

    Find the Mistake Easy
  67. 67

    Find: Incorrect Interface

    Find the error in an object that doesn't match its interface.

    Find the Mistake Easy
  68. 68

    Find: Missing Optional Property

    Find the error when accessing an optional property without checking.

    Find the Mistake Medium
  69. 69

    Find: Wrong Tuple Type

    Find the error in a tuple that doesn't match its type.

    Find the Mistake Medium
  70. 70

    Find: Incorrect Enum

    Find the error in an enum access.

    Find the Mistake Easy
  71. 71

    Find: Missing Readonly

    Find the error when mutating a readonly array.

    Find the Mistake Medium
  72. 72

    Find: Wrong Utility Type

    Find the error when using the wrong utility type.

    Find the Mistake Medium
  73. 73

    Find: Incorrect Mapped Type

    Find the error in a mapped type that doesn't transform correctly.

    Find the Mistake Medium
  74. 74

    Find: Wrong Conditional Type

    Find the error in a conditional type that resolves incorrectly.

    Find the Mistake Medium
  75. 75

    Find: Missing Type Parameter

    Find the error when a generic type parameter is not provided.

    Find the Mistake Medium
  76. 76

    Find: Incorrect Type Narrowing

    Find the error in a type narrowing that doesn't work as expected.

    Find the Mistake Medium
  77. 77

    Find: Wrong Function Overload

    Find the error in function overloads that don't match the implementation.

    Find the Mistake Medium
  78. 78

    Find: Missing Null Check

    Find the error when accessing a property without a null check.

    Find the Mistake Easy
  79. 79

    Find: Incorrect Type Import

    Find the error in a type-only import.

    Find the Mistake Medium
  80. 80

    Find: Wrong Strict Mode Config

    Find the error caused by strict mode settings.

    Find the Mistake Medium
  81. 81

    Concept: Type Safety

    Check your understanding of what type safety means in TypeScript.

    Concept Check Easy
  82. 82

    Concept: Why TypeScript

    Understand the main benefits of using TypeScript over plain JavaScript.

    Concept Check Easy
  83. 83

    Concept: Structural Typing

    Understand TypeScript's structural (duck) typing system.

    Concept Check Medium
  84. 84

    Concept: Type Erasure

    Understand what happens to TypeScript types at runtime.

    Concept Check Easy
  85. 85

    Concept: Compile-Time vs Runtime

    Understand the distinction between compile-time and runtime in TypeScript.

    Concept Check Medium
  86. 86

    Concept: Type Widening

    Understand type widening and when TypeScript generalizes literal types.

    Concept Check Medium
  87. 87

    Concept: Control Flow Analysis

    Understand how TypeScript narrows types through control flow.

    Concept Check Medium
  88. 88

    Concept: Exhaustiveness Checking

    Understand exhaustiveness checking with the never type in switch statements.

    Concept Check Medium
  89. 89

    Concept: Declaration Merging

    Understand declaration merging with interfaces.

    Concept Check Medium
  90. 90

    Concept: Type vs Interface

    Understand when to use type aliases vs interfaces.

    Concept Check Medium
  91. 91

    Concept: When to Use Generics

    Understand the scenarios where generics are the right choice.

    Concept Check Medium
  92. 92

    Concept: Type Inference Benefits

    Understand the advantages of TypeScript's type inference system.

    Concept Check Easy
  93. 93

    Concept: Strict Mode Benefits

    Understand the safety benefits of TypeScript's strict mode.

    Concept Check Medium
  94. 94

    Concept: Migration from JS

    Understand the strategy for migrating JavaScript to TypeScript.

    Concept Check Medium
  95. 95

    Concept: tsconfig Importance

    Understand the role of tsconfig.json in a TypeScript project.

    Concept Check Easy
  96. 96

    Concept: Best Practices

    Understand key TypeScript best practices for maintainable code.

    Concept Check Medium
  97. 97

    Concept: Soundness

    Understand type system soundness and its limitations in TypeScript.

    Concept Check Medium
  98. 98

    Concept: Type Compatibility

    Understand how TypeScript determines type compatibility.

    Concept Check Medium
  99. 99

    Concept: Variance

    Understand variance in TypeScript's generic types.

    Concept Check Medium
  100. 100

    Concept: Declaration Files

    Understand the purpose of .d.ts declaration files.

    Concept Check Medium
  101. 101

    TS Purpose

    What is the primary purpose of TypeScript?

    Multiple Choice Beginner
  102. 102

    Type Inference

    When does TypeScript infer types?

    Multiple Choice Beginner
  103. 103

    Interface vs Type

    What is the difference between interface and type alias?

    Multiple Choice Easy
  104. 104

    Union Type

    What does a union type A | B mean?

    Multiple Choice Beginner
  105. 105

    Intersection Type

    What does an intersection type A & B mean?

    Multiple Choice Easy
  106. 106

    Type Guard Purpose

    What is a type guard?

    Multiple Choice Easy
  107. 107

    Generics Purpose

    Why use generics in TypeScript?

    Multiple Choice Easy
  108. 108

    Enum Numeric

    What does this enum produce? enum Direction { Up, Down, Left, Right }

    Multiple Choice Beginner
  109. 109

    String Enum

    What is a string enum?

    Multiple Choice Easy
  110. 110

    Optional Chaining

    What does optional chaining (?.) do?

    Multiple Choice Beginner
  111. 111

    Nullish Coalescing

    What does nullish coalescing (??) do?

    Multiple Choice Beginner
  112. 112

    Tuple Type

    What is a tuple type in TypeScript?

    Multiple Choice Easy
  113. 113

    Utility Partial

    What does Partial<T> do?

    Multiple Choice Easy
  114. 114

    Utility Pick

    What does Pick<T, K> do?

    Multiple Choice Easy
  115. 115

    Utility Omit

    What does Omit<T, K> do?

    Multiple Choice Easy
  116. 116

    Utility Readonly

    What does Readonly<T> do?

    Multiple Choice Easy
  117. 117

    Conditional Type

    What is a conditional type?

    Multiple Choice Medium
  118. 118

    Mapped Type

    What is a mapped type?

    Multiple Choice Medium
  119. 119

    Type Narrowing

    What is type narrowing?

    Multiple Choice Easy
  120. 120

    Strict Mode

    What does strict: true enable in tsconfig?

    Multiple Choice Easy
  121. 121

    Type vs Interface Choice

    When should you prefer type over interface?

    Multiple Choice Easy
  122. 122

    Const Assertion

    What does "as const" do?

    Multiple Choice Medium
  123. 123

    Discriminated Union

    What is a discriminated union?

    Multiple Choice Medium
  124. 124

    Function Overloads

    What are function overloads in TypeScript?

    Multiple Choice Medium
  125. 125

    Generic Constraints

    What does "T extends SomeType" do in a generic?

    Multiple Choice Medium
  126. 126

    Never Type

    What is the never type?

    Multiple Choice Medium
  127. 127

    Unknown vs Any

    How does unknown differ from any?

    Multiple Choice Medium
  128. 128

    Type Assertion

    What is a type assertion (as)?

    Multiple Choice Easy
  129. 129

    TS Compilation

    What does the TypeScript compiler do?

    Multiple Choice Easy
  130. 130

    Declaration Files

    What is a .d.ts file?

    Multiple Choice Medium
  131. 131

    Type Inference Number

    Predict the output.

    Predict Output Beginner
  132. 132

    Const Literal Type

    Predict the output.

    Predict Output Easy
  133. 133

    Union Narrowing

    Predict the output.

    Predict Output Easy
  134. 134

    Enum Value

    Predict the output.

    Predict Output Beginner
  135. 135

    String Enum Value

    Predict the output.

    Predict Output Easy
  136. 136

    Optional Chaining Null

    Predict the output.

    Predict Output Beginner
  137. 137

    Nullish Coalescing Zero

    Predict the output.

    Predict Output Easy
  138. 138

    Tuple Access

    Predict the output.

    Predict Output Beginner
  139. 139

    Partial Type

    Predict the output.

    Predict Output Easy
  140. 140

    Pick Type

    Predict the output.

    Predict Output Easy
  141. 141

    Type Guard Custom

    Predict the output.

    Predict Output Medium
  142. 142

    Generic Identity

    Predict the output.

    Predict Output Beginner
  143. 143

    Keyof Type

    Predict the output.

    Predict Output Medium
  144. 144

    Indexed Access

    Predict the output.

    Predict Output Medium
  145. 145

    Readonly Property

    Predict the output.

    Predict Output Easy
  146. 146

    Conditional Type Result

    Predict the output.

    Predict Output Medium
  147. 147

    Discriminated Union Narrow

    Predict the output.

    Predict Output Medium
  148. 148

    Omit Type

    Predict the output.

    Predict Output Easy
  149. 149

    Record Type

    Predict the output.

    Predict Output Easy
  150. 150

    Never in Switch

    Predict the output.

    Predict Output Medium

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects