O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interfaces

An interface is an abstract type that defines the behavior of a class. It provides a type definition for an object that can be exchanged between clients. This enables the client to only exchange an object that is compiled with the interface type definition; otherwise, we get a compile time error.

In TypeScript, interfaces define contracts of an object within your code and the code outside your project. Let's see how to use TypeScript with an example:

function addCustomer(customerObj: {name: string}) {   console.log(customerObj.name); } let customer = {id: 101, name: "Rajesh Gunasundaram"}; addCustomer(customer); 

The type-checker verifies the addCustomer method call and examines its parameter. The addCustomer expects an object ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required