Getting ready

Let's create a new file with the .ts extension, name it main-0, and write the following code in it:

interface Customer { 
    name: string; 
    email: string; 
    phone: string; 
} 
 
let customers: Array<Customer> = []; 
 
customers.push({ 
    name: 'Engin Polat', 
    email: 'engin@enginpolat.com', 
    phone: '0123456789' 
}); 

As you can see, Typescript allows us to define the interface in the code and add properties in it. Every property can have a type, and all assignments to that property must be that type. Otherwise, the Typescript tsc will throw an exception and will not transpile the Typescript code into JavaScript code.

Let's also write the following code and examine it:

class Product { public title: string; public price: number; private updatedOn: ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.