A Learning TypeScript > Using IDE Features 🍲 entree project.
Have you ever written code meant only to be temporary? Did you say something hopeful like "we'll clean this up after release" before committing it?
Well, I did. And now the "temporary" code is a core part of my record-keeping program that shouldn't change. The irony is not lost on me, thank you very much.
I'd like you to perform several refactors on the code in
./index.ts to help us modernize the old code.
Each of these should correspond to a refactor provided by TypeScript.
- Rename the
- Add an explicit inline return type to the function
- Extract that return type to an interface named
- Infer the type for the
- Move the
Persontype to a new file,
- Convert the
describePersonfunction's string concatenation to a template literal string
- Select the
ifstatement -including its contents- and extract it to a function in module scope named
- Move the
criticizePersonfunction to a new file,
In life, there are but three certainties: death, taxes, and temporary code. -Josh Goldberg, 2022
src/index.ts: Refactor the functions here
src/index.test.ts: Tests verifying the refactored functions
./src/Person.solution.ts: Solution code
- Don't directly write any code. You should be able to complete this entire project using only refactors provided by TypeScript.
- Other than any shortcuts you choose to use, the only typing you should perform on your keyboard should be selecting names in refactor prompts.