Software Development free courses

Master the TrickFoundationFree

TypeScript Foundations

Describe data with TypeScript types and distinguish compile-time checking from runtime validation.

3 reading lessons · about 30 min ·written by MTT

The idea

TypeScript checks JavaScript programs using types. It can infer a type from a value or use an explicit annotation. Interfaces and type aliases describe shapes; they do not create runtime objects or automatically check data received from the network.

Worked example

A product shape requires an id string and a price number. Assigning a string price to a value checked against that shape produces a type error. Receiving the same bad shape through an unchecked network response still needs a runtime check.

Try it

Sketch a product type with three fields and two sample values, one valid and one invalid. Identify the expected static error. Write why a declared type on a fetched response would not alone prove the actual response matches it.

Lesson 1 of 3 · About 10 min

Describe values and contracts

Check your understanding

Course quiz

Finish the course to unlock the quiz

Complete all 3 lessons and 5 questions open up here. You have 3 to go.

What you will learn

  • Explain inference and type annotations
  • Narrow union types before use
  • Validate external data at runtime

Before you start

Prerequisites
Basic JavaScript familiarity. Examples can be traced on paper or in a local TypeScript project.
Cost
Free introductory reading lessons, exercises and quiz. Optional third-party tools, hosting or AI subscriptions may cost money.

Original introductory lessons and assessment by Master the Trick. Estimated times include the suggested exercises.