Skip to content

TypeScript Project for Beginners: Build a Typed Order Summary with VAT and Promo Codes

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

This project puts the whole course into one small feature that a real shop could use: an order summary. A customer picks a product, a quantity and maybe a promo code, and the page shows the subtotal, the discount, 5 percent UAE VAT and the total. Nothing here is new on its own. What is new is how the pieces support each other: an interface describes the products, a type guard checks the catalogue before anything trusts it, a discriminated union makes every kind of discount explicit, money is kept in whole fils, and the DOM code uses the element types TypeScript already knows. When you finish, you can take the graded project test and the final exam for the TypeScript certificate.

Quick answer

Build it in five steps. Describe the data: interface Product { id: string; name: string; priceFils: number }. Parse the catalogue as unknown and keep only items that pass isProduct. Model discounts as { kind: "percent"; value: number } | { kind: "fixed"; fils: number }, list promo codes with satisfies Record<string, Discount>, and handle every kind in a switch that ends in never. Do all money maths in whole fils with Math.round, then format once with Intl.NumberFormat. Read inputs with querySelector<HTMLInputElement>, update on the input event and write with textContent. Finally, move the code into a project with strict mode and tsc --noEmit.

55 min read and practice · Content checked on 18 November 2026

In this lesson you will

  • Combine interfaces, unions, generics and narrowing in one feature
  • Check external data with a type guard before using it
  • Calculate money safely in whole fils, with VAT and discounts
  • Wire typed DOM elements and events into a working page

Step 1: describe the data and check it

Start with the shape of a product, because everything else depends on it: an id to find it, a name to show and a price. Store the price as a whole number of fils, priceFils: 4500 for 45 dirhams; you will see why in step 2. The catalogue arrives as JSON, here from a script tag, in a real shop from fetch. TypeScript cannot see inside it, so parse it as unknown, check that it is an array, and keep only the items that pass a type guard, isProduct(x: unknown): x is Product.

Decide what to do with bad data instead of letting it crash later. In a shop, a product with a missing price should simply not be offered, and someone should be told; that is why the guard checks every property and filter(isProduct) drops failures. Because the guard returns x is Product, the filtered array has the type Product[] with no cast. Check the details that matter for money too: a price must be a whole number, so the guard uses Number.isInteger.

Try it: Keep only valid products
Code
ResultUpdates as you type
Console
  1. Console messages, errors, form data and clicked links appear here.

The coffee has its price as the text "38", so the guard drops it and the shop offers two products instead of showing a wrong total later. products is a Product[] without any cast, because filter understands the type guard.

Sign in free to read the full lesson

You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.

Unlocks after sign-in:

  • 3 more sections with live code examples
  • Common mistakes to avoid
  • Hands-on coding exercise with automatic checks
  • Practice quiz and the graded lesson test
Sign in or create a free account

Free forever. No card, no paywall.

Questions people ask

What is a good first TypeScript project?

Something small with real data and real rules, like this order summary: it needs interfaces for data, a type guard for input, a union for choices and careful number handling. A to-do list is fine too, but a feature with money or validation shows better what types catch.

How do I avoid rounding errors with money in TypeScript?

Store amounts as whole numbers of the smallest unit, such as fils or cents, round with Math.round whenever a percentage creates a fraction, and convert to the main unit only for display with Intl.NumberFormat. TypeScript itself has only one number type, so this is a design choice, not a type.

How does a shop apply UAE VAT to a discounted order?

At the standard 5 percent rate, in force since 1 January 2018, VAT is charged on the price after the discount, and some supplies are zero-rated or exempt. Check the Federal Tax Authority for the current rules before using a rate in a real shop, and keep the rate in data so it is easy to change.

How do I get the TypeScript certificate?

Sign in, pass the short test after each lesson, the three module tests and the graded project, then the final exam. The certificate shows your name and a verification code that anyone can check on this site. It is free, like the course.

What should I learn after TypeScript?

Use it in a framework. React with TypeScript is the most common next step for front end work, and Node.js with TypeScript for servers and APIs. Both use everything from this course: interfaces for props and data, unions for state, generics in hooks and libraries, and strict mode.

Sources

Facts in this lesson were checked against these official pages on 18 November 2026.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.