Skip to main content

Medium Challenges

Medium challenges build on the fundamentals and introduce more complex type manipulation patterns. You’ll work with recursive types, string manipulation, and advanced conditional logic.
Total Challenges: 103 | Recommended for: Developers comfortable with TypeScript basics

Challenge Categories

Medium challenges are organized into several categories:

Object Manipulation (15 challenges)

#3 - Omit

Remove properties from types

#8 - Readonly 2

Make specific properties readonly

#527 - Append to Object

Add properties to object types

#599 - Merge

Merge two object types

String Manipulation (20 challenges)

#106 - Trim Left

Remove leading whitespace from string types

#108 - Trim

Remove whitespace from both ends

#110 - Capitalize

Capitalize first character

#116 - Replace

Replace string patterns

Array & Tuple Operations (25 challenges)

#10 - Tuple to Union

Convert tuple to union type

#15 - Last of Array

Get last element type

#16 - Pop

Remove last element from tuple

#459 - Flatten

Flatten nested array types

All Medium Challenges

  1. #2 - Get Return Type
  2. #3 - Omit
  3. #8 - Readonly 2
  4. #9 - Deep Readonly
  5. #10 - Tuple to Union
  6. #12 - Chainable Options
  7. #15 - Last of Array
  8. #16 - Pop
  9. #20 - Promise.all
  10. #62 - Type Lookup
  11. #106 - Trim Left
  12. #108 - Trim
  13. #110 - Capitalize
  14. #116 - Replace
  15. #119 - ReplaceAll
  16. #191 - Append Argument
  17. #296 - Permutation
  18. #298 - Length of String
  19. #459 - Flatten
  20. #527 - Append to object
  21. #529 - Absolute
  22. #531 - String to Union
  23. #599 - Merge
  24. #612 - KebabCase
  25. #645 - Diff
  26. #949 - AnyOf
  27. #1042 - IsNever
  28. #1097 - IsUnion
  29. #1130 - ReplaceKeys
  30. #1367 - Remove Index Signature
  31. #1978 - Percentage Parser
  32. #2070 - Drop Char
  33. #2257 - MinusOne
  34. #2595 - PickByType
  35. #2688 - StartsWith
  36. #2693 - EndsWith
  37. #2757 - PartialByKeys
  38. #2759 - RequiredByKeys
  39. #2793 - Mutable
  40. #2852 - OmitByType
  41. #2946 - ObjectEntries
  42. #3062 - Shift
  43. #3188 - Tuple to Nested Object
  44. #3192 - Reverse
  45. #3196 - Flip Arguments
  46. #3243 - FlattenDepth
  47. #3326 - BEM style string
  48. #4179 - Flip
  49. #4182 - Fibonacci Sequence
  50. #4260 - AllCombinations
  51. #4425 - Greater Than
  52. #4471 - Zip
  53. #4484 - IsTuple
  54. #4499 - Chunk
  55. #4518 - Fill
  56. #4803 - Trim Right
  57. #5117 - Without
  58. #5140 - Trunc
  59. #5153 - IndexOf
  60. #5310 - Join
  61. #5317 - LastIndexOf
  62. #5360 - Unique
  63. #5821 - MapTypes
  64. #7544 - Construct Tuple
  65. #8640 - Number Range
  66. #8767 - Combination
  67. #8987 - Subsequence
  68. #9142 - CheckRepeatedChars
  69. #9286 - FirstUniqueCharIndex
  70. #9616 - Parse URL Params
  71. #9896 - GetMiddleElement
  72. #9898 - Appear only once
  73. #9989 - Count Element Number To Object
  74. #10969 - Integer
  75. #16259 - ToPrimitive
  76. #17973 - DeepMutable
  77. #18142 - All
  78. #18220 - Filter
  79. #19749 - IsEqual
  80. #21104 - FindAll
  81. #21106 - Combination key type
  82. #21220 - Permutations of Tuple
  83. #25170 - Replace First
  84. #25270 - Transpose
  85. #26401 - JSON Schema to TypeScript
  86. #27133 - Square
  87. #27152 - Triangular number
  88. #27862 - CartesianProduct
  89. #27932 - MergeAll
  90. #27958 - CheckRepeatedTuple
  91. #28333 - Public Type
  92. #29650 - ExtractToObject
  93. #29785 - Deep Omit
  94. #30301 - IsOdd
  95. #30430 - Tower of hanoi
  96. #30958 - Pascal’s triangle
  97. #30970 - IsFixedStringLiteralType
  98. #34007 - Compare Array Length
  99. #34857 - Defined Partial Record
  100. #35045 - Longest Common Prefix
  101. #35191 - Trace
  102. #35252 - IsAlphabet
  103. #35991 - MyUppercase

Try any challenge

Open Type Challenges playground

Description

Implement the built-in Omit<T, K> generic without using it. Constructs a type by picking all properties from T and then removing K.

Example

interface Todo {
  title: string
  description: string
  completed: boolean
}

type TodoPreview = MyOmit<Todo, 'description' | 'title'>

const todo: TodoPreview = {
  completed: false,
}

Key Concepts

  • Combining Pick and Exclude
  • Property filtering
  • Key manipulation

Try this challenge

Open in TypeScript Playground

Description

Implement a chainable object that allows setting options with proper type inference for each step in the chain.

Example

declare const config: Chainable

const result = config
  .option('foo', 123)
  .option('name', 'type-challenges')
  .option('bar', { value: 'Hello World' })
  .get()

// result is { foo: number, name: string, bar: { value: string } }

Key Concepts

  • Builder pattern in types
  • Accumulating type state
  • Method return type inference

Try this challenge

Open in TypeScript Playground

Description

Implement Capitalize<T> that converts the first letter of a string to uppercase and leaves the rest as-is.

Example

type capitalized = Capitalize<'hello world'> // 'Hello world'
type alreadyCapitalized = Capitalize<'TypeScript'> // 'TypeScript'

Key Concepts

  • Template literal types
  • String intrinsic types
  • Pattern matching on strings

Try this challenge

Open in TypeScript Playground

Description

Implement a type that returns all permutations of a union type.

Example

type perm = Permutation<'A' | 'B' | 'C'>
// Result: ['A', 'B', 'C'] | ['A', 'C', 'B'] | ['B', 'A', 'C'] | 
//         ['B', 'C', 'A'] | ['C', 'A', 'B'] | ['C', 'B', 'A']

Key Concepts

  • Union distribution
  • Recursive type generation
  • Tuple construction

Try this challenge

Open in TypeScript Playground

Description

Compute the length of a string literal type.

Example

type len1 = LengthOfString<'hello'> // 5
type len2 = LengthOfString<'type-challenges'> // 15

Key Concepts

  • String parsing with template literals
  • Accumulator pattern
  • Recursive type processing

Try this challenge

Open in TypeScript Playground

Core Patterns for Medium Challenges

1. Deep Recursion

Process nested structures recursively:
type DeepReadonly<T> = {
  readonly [K in keyof T]: T[K] extends object 
    ? DeepReadonly<T[K]> 
    : T[K]
}

2. Template Literal Types

Manipulate string types:
type KebabCase<S extends string> = S extends `${infer C}${infer T}`
  ? C extends Uppercase<C>
    ? `-${Lowercase<C>}${KebabCase<T>}`
    : `${C}${KebabCase<T>}`
  : S

3. Tuple Recursion

Process arrays element by element:
type Reverse<T extends any[]> = T extends [infer F, ...infer R]
  ? [...Reverse<R>, F]
  : []

4. Union Distribution

Distribute operations over union members:
type Permutation<T, K=T> = [T] extends [never]
  ? []
  : K extends K
    ? [K, ...Permutation<Exclude<T, K>>]
    : never

5. Type-Level Math

Perform calculations at the type level:
type MinusOne<T extends number, A extends any[] = []> = 
  [...A, any]['length'] extends T
    ? A['length']
    : MinusOne<T, [...A, any]>

Tips for Medium Challenges

Many medium challenges require recursion. Practice with simple recursive types first:
// Base case: empty array
type Reverse<T extends any[]> = T extends [] ? [] : ...

// Recursive case: process one element
type Reverse<T extends any[]> = T extends [infer F, ...infer R]
  ? [...Reverse<R>, F]
  : []
String manipulation uses template literals extensively:
// Match pattern: first character + rest
type Capitalize<S> = S extends `${infer F}${infer R}`
  ? `${Uppercase<F>}${R}`
  : S
Conditional types distribute over unions automatically:
type ToArray<T> = T extends any ? [T] : never
type Result = ToArray<'A' | 'B'> // ['A'] | ['B']
Break complex problems into smaller pieces:
type IsNever<T> = [T] extends [never] ? true : false
type IsUnion<T> = ... // use IsNever as a helper
Always test with:
  • Empty arrays/strings
  • Single elements
  • Nested structures
  • Never and unknown types

Learning Path

1

Object Utilities (3, 8, 527, 599)

Start with object manipulation challenges
2

String Basics (106, 108, 110, 116)

Learn template literal type patterns
3

Recursion (9, 459, 3192)

Master recursive type processing
4

Advanced Patterns (12, 296, 298)

Tackle complex type-level algorithms
5

Type Math (2257, 4182, 4425)

Learn type-level arithmetic

Next Steps

Ready for more advanced challenges?

Hard Challenges

55 challenges for advanced TypeScript mastery

Template Literals

Deep dive into template literal types