Grokking TypeScript
Vote

0% completed

​

Understanding Object Types

An object groups related values under named properties. In plain JavaScript, nothing stops a program from leaving one of those properties out or storing the wrong kind of value in it. TypeScript lets you write down which properties an object must have and what type each one holds, and that description is called an object type.

Describing an Object with an Inline Type

Start with an ordinary object.

const user = { name: "John Doe", age: 25, };

JavaScript accepts this object, and it would equally accept a copy with no age, or a copy whose age is the string

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content