Skip to main content

Template Literal Type Shenanigans

A Learning TypeScript > Type Operations 🥗 appetizer project.

Hi! This is Josh, author of Learning TypeScript. Congrats on making it all the way through the book to the final chapter! Type operations are a ton of fun to play around with once you get the hang of them.

These appetizer projects showcase a bunch of my favorite cool things you can do using template literal types with conditional types. Each gives a small into to the new thing because it can be tricky to find out the ways you can or cannot combine type operations. There's no silly theme, to help not distract from learning those new things.

I hope you're enjoying the book and these projects! 💖

Setup

If you haven't yet, set up the github.com/LearningTypeScript/projects repository locally.

git clone https://github.com/LearningTypeScript/projects learning-typescript-projects
cd learning-typescript-projects
npm i

Change your terminal directory to this project's:

cd projects/type-operations/template-literal-type-shenanigans

Start the TypeScript compiler in watch mode:

tsc --watch

Steps

Notes

  • Don't import code from one step into another.
  • You'll be working entirely in the type system. There will be no runtime code. 🤘