June 2015
Intermediate to advanced
192 pages
4h 8m
English
An interface defines how something behaves, without defining the implementation. In TypeScript, an interface names a complex type by describing the fields it has. This is known as structural subtyping.
Declaring an interface is a little like declaring a structure or class; you define the fields in the interface, each with its own type, like this:
interface Record {
call: string;
lat: number;
lng: number;
}
Function printLocation(r: Record) {
console.log(r.call + ': ' + r.lat + ', ' + r.lng);
}
var myObj = {call: 'kf6gpe-7', lat: 21.9749, lng: 159.3686};
printLocation(myObj);The interface keyword in TypeScript defines an interface; as I already noted, an interface consists of the ...
Read now
Unlock full access