July 2017
Intermediate to advanced
454 pages
10h 1m
English
An interface is an abstract type that defines the behavior of a class. An interface is a contract that abstracts the implementation. An interface provides a type definition for an object that can be exchanged between clients. This enables the client to only exchange an object that is complied with the interface type definition. Otherwise, we get a compile time error.
In TypeScript, interfaces define contracts for 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);
}
var customer = {id: 101, name: "Rajesh Gunasundaram"};
addCustomer(customer);
The type checker verifies the addCustomer method ...
Read now
Unlock full access