M Logo
๐Ÿ“ TypeScript from Zero ยท Part 9 of 50

TypeScript Objects: Properties, Dot vs Brackets (and a Missing Property Error)

November 6, 2026

Welcome to episode 9 of TypeScript from Zero, a series for complete beginners (no JavaScript needed). Welcome back to TypeScript from zero! Today: objects. An object groups related values together, each one under its own name. A new file called objects.ts. Every code block below is the code from the video, ready to copy; run each file to see the output.

Setup

We start in the terminal and open the project in VS Code:

bash
$ touch objects.ts

1. Create

We write an object with curly braces. Inside, every property has a name, a colon, and a value, and the properties are separated by commas. This user has a name and an age. We print the whole object.

ts
const user = { name: "Mia", age: 30 };
console.log(user);
bash
$ node objects.ts

2. Read

We read one property with a dot: user dot name. We can also use square brackets with the name as text. Both give the same result. The dot is shorter, so we use it most of the time.

ts
console.log(user.name);
console.log(user["age"]);
bash
$ node objects.ts

3. Change

Our user is a constant, but we can still change a property inside it. The constant only means that the name user always points to the same object. Now the age is thirty one.

ts
user.age = 31;
console.log(user);
bash
$ node objects.ts

4. Nested

A property can hold another object. Here the book has an author, and the author has a name and a year. We read it step by step, with two dots: book dot author dot name.

ts
const book = { title: "Dune", author: { name: "Frank", born: 1920 } };
console.log(book.author.name);
bash
$ node objects.ts

5. Missing

What if we ask for a property that does not exist, like email? Node does not crash. It just gives us undefined, and a small mistake like that can travel far through a program.

ts
console.log(user.email);
bash
$ node objects.ts

6. tsc

tsc stops it at once: property email does not exist on this type, and it even shows the exact shape of our object. The code is TS2339. TypeScript knows every property we gave the object.

bash
$ npx tsc --noEmit objects.ts

7. Fix

We delete that line, and tsc is quiet again.

bash
$ npx tsc --noEmit objects.ts

Recap

Today: objects with curly braces, reading with a dot or with brackets, changing a property of a constant, nested objects, and the error for a missing property. Next episode: functions.

ยฉ 2026 All Rights Reserved By Mahmudul Alam