Prickly Predicates
A Learning TypeScript > Type Modifiers π₯ appetizer project.
Howdy ho, farmer friend!
Here at π΅ Cultured Cacti π΅, we cultivate the crΓ¨me de la crΓ¨me of cactus, cassava, and chia. Any plant that reminds you of savannahs, South America, and the American Southwest are our claim to fame. Yee-haw!
We reckon our industry could be much improved by some spring cleaning of our code. We'd like to prepare a trio of TypeScript type predicates to wrangle our unruly data types. Are you up for the challenge, partner?
Setupβ
If you haven't yet, set up the github.com/LearningTypeScript/projects repository locally.
shellgit clone https://github.com/LearningTypeScript/projects learning-typescript-projectscd learning-typescript-projectsnpm i
shellgit clone https://github.com/LearningTypeScript/projects learning-typescript-projectscd learning-typescript-projectsnpm i
Open your editor in this project's directory:
shellcode projects/type-modifiers/prickly-predicates
shellcode projects/type-modifiers/prickly-predicates
In one terminal, run the TypeScript compiler via the tsc script within whichever step you're working on.
For example, to start the TypeScript compiler on the first step in watch mode:
shellnpm run tsc -- --project 01-pruning-pests --watch
shellnpm run tsc -- --project 01-pruning-pests --watch
In another terminal, run Jest via the test script on whichever step you're working on.
For example, to start tests for the first step in watch mode:
shellnpm run test -- 1 --watch
shellnpm run test -- 1 --watch
Note: your terminal should be in the
prickly-predicatesdirectory, not the root repository's directory.
Stepsβ
Notesβ
- Don't import code from one step into another.
- For each type predicate function, explicitly write the return type with
is- Don't rely on TypeScript 5.5's inferred type predicates