-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learn React with TypeScript
By :

The last section showed that TypeScript has a great set of standard types. In this section, we will learn how to create our own types. We will start by learning how to create types for objects before learning how to create types for variables that hold a range of values.
Objects are very common in JavaScript programs, so learning how to represent them in TypeScript is really important. In fact, we already used an object type earlier in this chapter for the product
parameter in the calculateTotalPrice
function. Here is a reminder of the product
parameter’s type annotation:
function calculateTotalPrice( product: { name: string; unitPrice: number }, ... ) { ... }
An object type in TypeScript is represented a bit like a JavaScript object literal. However, instead of property values, property types are specified instead. Properties in the object definitions can be separated by semicolons...