Extreme TypeScript Challenges

Only for the most experienced TypeScript developers. Proceed with caution!

#5

Get Readonly Keys

Collect the readonly keys of an object type into a union. Assignability is blind to readonly, so the check has to be an identity comparison per key.

ExtremePro
#151

Query String Parser

Parse a URL query string into an object type. Bare keys become true, repeated values are deduplicated, and a key with one value keeps that value unwrapped.

ExtremePro
#216

Slice

Implement Array.slice in the type system. Start and End are optional, negative indexes count from the end, and out-of-range values collapse to an empty tuple.

Extreme
#274

Integers Comparator

Compare two numeric literal types and return Greater, Equal or Lower. With no comparison operator available, the work happens on the digits of the stringified numbers.

ExtremePro
#462

Currying 2

Type a curry helper that accepts any number of arguments per call. Partial over the parameter tuple describes the legal prefixes, and each call drops what it consumed.

ExtremePro
#476

Sum

Add two non-negative integers of any size in the type system. Long addition over digit strings, with tuple lengths standing in for the arithmetic.

ExtremePro
#517

Multiply

Multiply two non-negative integers in the type system. Long multiplication over digit strings, built from a shift and repeated addition.

ExtremePro
#697

Tag

Attach nominal tags to any type without breaking assignability. Six types that add, read, match and strip tags that live where structural comparison cannot see them.

ExtremePro
#734

Inclusive Range

Build the tuple of every integer from Lower to Higher, both included. The recursion depth limit is the real obstacle, and tail recursion is the way past it.

Extreme
#741

Sort

Sort a tuple of natural numbers, ascending or descending, without any arithmetic. Comparison comes out of tuple lengths, insertion sort does the rest.

ExtremePro
#869

DistributeUnions

Expand every union nested inside objects and tuples into a union of union-free structures. The cartesian product is built one key and one element at a time.

ExtremePro
#925

Assert Array Index

Write an assert function that tags an array so only an index derived from that tag may read its elements. Every other index becomes a type error.

ExtremePro
#6228

JSON Parser

Parse a JSON string into an object literal type. A character-level tokenizer feeds a recursive descent parser, and invalid input has to collapse to never.

ExtremePro
#7561

Subtract

Subtract one number literal from another by building tuples and peeling one off the other. TypeScript's 1000-step recursion budget is part of the puzzle.

ExtremePro
#31447

CountReversePairs

Count every pair in a tuple where an earlier number is larger than a later one, using tuple-length arithmetic and a comparison that handles negatives.

ExtremePro
#31997

Parameter Intersection

Merge two parameter tuples into the argument list that satisfies both, keeping required, optional and rest positions straight while intersecting element types.

ExtremePro
#33345

Dynamic Route

Infer the params object of a file-based route from its path, covering catch-all and optional catch-all segments, and returning never when two catch-alls are ambiguous.

ExtremePro

Congratulations on reaching the extreme level! Keep practicing with all TypeScript challenges to maintain your edge.