Skip to main content

Primitive Cooking

A Learning TypeScript > Unions and Literals 🥗 appetizer project.

Those pesky Java programmers are at it again!

I wrote a few functions for a friend to help arrange meals when I have guests over. The friend worked with their enterprise application development team to "improve" the code. Next thing I know, they've replaced all my TypeScript-y literal and union types with plain old primitive types.

Those Java fans are perfectly good developers -and lovely people- but we don't see eye-to-eye on type systems. Now TypeScript is reporting type errors on my code. Could you please correct the type annotations in my files -- and maybe a couple bugs the improved types helped TypeScript find?

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/unions-and-literals/primitive-cooking

Start the TypeScript compiler in watch mode:

tsc --watch

Steps

Notes

  • Most of the changes you'll be making are to type annotations.
    • The only changes to runtime code behavior will be small typo fixes.
  • Don't use any.