Have you ever tried writing your own Uppercase utility type in TypeScript?
Utility types like Uppercase<T> in TypeScript allow us to perform powerful compile-time transformations on string types.
Utility types like Uppercase<T> in TypeScript allow us to perform powerful compile-time transformations on string types. However, we sometimes gain a much deeper understanding by implementing them from scratch ourselves.

For instance, the following Uppercase<T> implementation converts every character of a string to uppercase, except we are doing this transformation through a manually written character map called Chars.
π‘ Whatβs happening here?
- If
Tis a string, we split it into two parts:FirstandTail. - We check the
Firstcharacter against theCharsmap β if it exists, we convert it to uppercase. - Next, we recursively transform the remaining part using
Uppercase<Tail>. - Once we reach the end of the string (
T extends ''), the recursion terminates with an empty string.
π§ As a result, we've built a real Uppercase transformation using recursive conditional types and distributive string literal pattern matching!
If you also want to understand the type system on a deeper level β try writing small experiments like this yourself π¨βπ»
#typescript #typelevelprogramming #generics #utilitytypes #codewithme #devtips #softwareengineering