上QQ阅读APP看书,第一时间看更新
Writing JavaScript code with static types
The first thing that you'll notice when working with TypeScript are its static types, in addition to all of the JavaScript types, indicated on the following table:
Primitives Objects
String Function
Number Array
Null Prototypes
Undefined
Boolean
Symbol
This means that you can declare the types of variables; it's pretty simple to assign a type to a variable. Let's look at some examples, using JavaScript types only:
function Myband () {
let band: string;
let active: boolean;
let numberOfAlbuns: number;
}
With TypeScript, we have a few more types, as we'll see in the following sections.