TypeScript in practice

Write TypeScript from your first typed function to a typed event emitter, and pass checks on both what the code does and what its types allow.

  1. 01

    Add Types to a Function's Parameters

    • easy
    • Code
  2. 02

    Describe an Object with a Type

    • easy
    • Code
  3. 03

    Make a Parameter Optional

    • easy
    • Code
  4. 04

    Accept Only a Few Exact Strings

    • easy
    • Code
  5. 05

    Type an Array of Numbers

    • easy
    • Code
  6. 06

    Allow Two Kinds of Value

    • easy
    • Code
  7. 07

    Return a Value or Nothing

    • easy
    • Code
  8. 08

    Write Your First Generic Function

    • easy
    • Code
  9. 09

    Pick Keys from an Object, Typed

    • easy
    • Code
  10. 10

    Return a Result Instead of Throwing

    • easy
    • Code
  11. 11

    Handle Every Case of a Union

    • easy
    • Code
  12. 12

    Check Unknown Data with a Type Guard

    • easy
    • Code
  13. 13

    Zip Two Lists into Typed Pairs

    • easy
    • Code
  14. 14

    Chunk a List, Keeping the Item Type

    • easy
    • Code
  15. 15

    Get the First Item, Typed by Length

    • easy
    • Code
  16. 16

    Fill In Options So Every Key Is Set

    • easy
    • Code
  17. 17

    Drop Duplicates by Key, Keeping Item Types

    • easy
    • Code
  18. 18

    Describe Each State of Remote Data

    • easy
    • Code
  19. 19

    Assert a Value Is a Non-empty String

    • easy
    • Code
  20. 20

    Filter Logs by a Typed Level

    • easy
    • Code
  21. 21

    Describe Errors by Their Class

    • easy
    • Code
  22. 22

    Parse Keyboard Shortcuts into Typed Keys

    • easy
    • Code
  23. 23

    Make a Read-Only Object Writable Again

    • easy
    • Code
  24. 24

    Keep Only an Object's String Fields

    • easy
    • Code
  25. 25

    Flatten Nested Arrays One Level, Typed

    • easy
    • Code
  26. 26

    List an Object's Values with Their Types

    • easy
    • Code
  27. 27

    Join Two Tuples, Position by Position

    • easy
    • Code
  28. 28

    Write a Generic Stack Class

    • easy
    • Code
  29. 29

    Write a Typed Observable Subject

    • easy
    • Code
  30. 30

    Share Behaviour Through an Abstract Class

    • easy
    • Code
  31. 31

    Guard a Balance with a Private Field

    • easy
    • Code
  32. 32

    Make a Class Iterable with Symbol.iterator

    • easy
    • Code
  33. 33

    Paginate a List with Typed Pages

    • easy
    • Code
  34. 34

    Check Feature Flags by Known Name

    • easy
    • Code
  35. 35

    Sort Table Rows by a Typed Column

    • easy
    • Code
  36. 36

    List Which Fields Changed, Typed

    • easy
    • Code
  37. 37

    Keep Milliseconds and Seconds Apart

    • easy
    • Code
  38. 38

    Build a Typed Deferred Promise

    • easy
    • Code
  39. 39

    Sleep Until Done or Aborted

    • easy
    • Code
  40. 40

    Time Out a Promise with a Typed Error

    • easy
    • Code
  41. 41

    Retry an Async Call, Keeping Its Result Type

    • easy
    • Code
  42. 42

    Poll Until a Typed Result Is Ready

    • easy
    • Code
  43. 43

    Cache a Function's Results, Keeping Its Types

    • medium
    • Code
  44. 44

    Group a List by a Computed Key

    • medium
    • Code
  45. 45

    Build a Typed Event Emitter

    • medium
    • Code
  46. 46

    Freeze Nested Data, Types Included

    • medium
    • Code
    • Pro
  47. 47

    Build a Query String from Typed Params

    • medium
    • Code
    • Pro
  48. 48

    Partition a List with a Type Guard

    • medium
    • Code
    • Pro
  49. 49

    Index a List by a Computed Key

    • medium
    • Code
  50. 50

    Map an Object's Values, Keeping Its Keys

    • medium
    • Code
  51. 51

    Omit Keys from an Object, Typed

    • medium
    • Code
  52. 52

    Curry a Two-Argument Function, Typed

    • medium
    • Code
  53. 53

    Count Items by a Computed Key

    • medium
    • Code
  54. 54

    Swap Keys and Literal Values, Typed

    • medium
    • Code
    • Pro
  55. 55

    Reduce Todo Actions from a Typed Union

    • medium
    • Code
  56. 56

    Model an Optional Value with Some and None

    • medium
    • Code
  57. 57

    Parse JSON Safely into a Checked Shape

    • medium
    • Code
  58. 58

    Tell Cats from Dogs by Their Properties

    • medium
    • Code
  59. 59

    Charge a Fee per Payment Method

    • medium
    • Code
  60. 60

    Summarise an Event Log by Kind

    • medium
    • Code
  61. 61

    Route Requests Through a Handler per Method

    • medium
    • Code
    • Pro
  62. 62

    Await an Object of Promises by Key

    • medium
    • Code
    • Pro
  63. 63

    Drop Null and Undefined Fields, Typed

    • medium
    • Code
  64. 64

    List an Object's Entries as Exact Pairs

    • medium
    • Code
    • Pro
  65. 65

    Merge Two Objects, Later Types Win

    • medium
    • Code
  66. 66

    Split a Tuple into Head and Tail

    • medium
    • Code
  67. 67

    Build an Enum Object from a List of Names

    • medium
    • Code
  68. 68

    Read Object Keys Without Losing Their Types

    • medium
    • Code
  69. 69

    Build a Typed LRU Cache Class

    • medium
    • Code
  70. 70

    Expire Cache Entries with an Injected Clock

    • medium
    • Code
  71. 71

    Write a Priority Queue Class with a Comparator

    • medium
    • Code
  72. 72

    Run and Undo Typed Commands

    • medium
    • Code
  73. 73

    Chain Results with Ok and Err Classes

    • medium
    • Code
  74. 74

    Look Up Plugins by Name, Fully Typed

    • medium
    • Code
  75. 75

    Subscribe to a Typed Slice of a Store

    • medium
    • Code
    • Pro
  76. 76

    Translate Messages by Known Keys

    • medium
    • Code
  77. 77

    Turn Environment Variables into Typed Config

    • medium
    • Code
    • Pro
  78. 78

    Add Up Prices in Whole Cents

    • medium
    • Code
  79. 79

    Read Search Params into a Typed Object

    • medium
    • Code
  80. 80

    Wrap Storage with Typed Keys and Values

    • medium
    • Code
    • Pro
  81. 81

    Check Whether Date Ranges Overlap

    • medium
    • Code
  82. 82

    Total a Cart with Typed Discounts

    • medium
    • Code
  83. 83

    Debounce a Function You Can Cancel, Typed

    • medium
    • Code
  84. 84

    Throttle a Function, Keeping Its Types

    • medium
    • Code
  85. 85

    Run Async Work Exclusively with a Typed Mutex

    • medium
    • Code
  86. 86

    Process Items One at a Time with a Typed Worker

    • medium
    • Code
  87. 87

    Map with a Concurrency Limit, Typed and in Order

    • medium
    • Code
    • Pro
  88. 88

    Share In-Flight Requests per Key, Typed

    • medium
    • Code
    • Pro
  89. 89

    Batch an Async Stream with a Typed Generator

    • medium
    • Code
  90. 90

    Keep Two Kinds of ID from Mixing Up

    • hard
    • Code
    • Pro
  91. 91

    Pipe a Value Through Typed Steps

    • hard
    • Code
    • Pro
  92. 92

    Build an Exact Object from Entries

    • hard
    • Code
  93. 93

    Sort by a Key That Holds Numbers or Strings

    • hard
    • Code
    • Pro
  94. 94

    Type a Traffic Light State Machine

    • hard
    • Code
    • Pro
  95. 95

    Chain Validation Steps, Keeping Every Error Type

    • hard
    • Code
    • Pro
  96. 96

    Read Typed Values from Form Fields

    • hard
    • Code
    • Pro
  97. 97

    Merge Overrides into Defaults at Any Depth

    • hard
    • Code
    • Pro
  98. 98

    Find the Required Fields Still Missing

    • hard
    • Code
  99. 99

    Bind Every Method to Its Object

    • hard
    • Code
    • Pro
  100. 100

    Make a Builder That Can't Build Too Early

    • hard
    • Code
    • Pro
  101. 101

    Resolve Typed Services from a DI Container

    • hard
    • Code
    • Pro
  102. 102

    Type a State Machine Class from Its Table

    • hard
    • Code
    • Pro
  103. 103

    Fetch JSON into a Validated Type

    • hard
    • Code
    • Pro
  104. 104

    Infer Types from a Validation Schema

    • hard
    • Code
    • Pro
  105. 105

    Parse CSV Rows with Typed Columns

    • hard
    • Code
  106. 106

    Limit Concurrent Work with a Typed Semaphore

    • hard
    • Code
  107. 107

    Settle a Tuple of Promises, Typed per Element

    • hard
    • Code
    • Pro
  108. 108

    Race Named Promises and Know Which Won

    • hard
    • Code
    • Pro