← All Exercises
Typed Pipe with Overloads
intermediatetypescript
Background
Function composition is a small utility with a surprisingly large type surface. Overloads make the composed function's input and output types precise instead of collapsing to any or unknown.
Problem
Implement pipe with overloads for one to four unary functions so each step's return type feeds the next step's parameter type. Build three typed pipelines: slugify (trim, lowercase, spaces to dashes), shout (trim, uppercase, append exclamation), and length (trim then string length). Select a preset from JSON input and print its result.
Input
A JSON object with value (a string) and preset (slugify, shout, or length).
Output
The pipeline result printed as a plain value: a string for slugify and shout, a number for length.
Sample tests
Sample 1
Input: {"value":" Hello World ","preset":"slugify"}Expected: hello-world
Sample 2
Input: {"value":" hi ","preset":"shout"}Expected: HI!
Sample 3
Input: {"value":" four ","preset":"length"}Expected: 4
Your solution
Learning objective
Understand overload signatures, function composition, and how types flow through a pipeline of unary functions.