TypeScript学习笔记
简介
TypeScript是微软推出的 JavaScript 的超集。
语法结构
如下
// boolean
let isDone: boolean = false
// number
let decimal: number = 6
let pi: number = 3.14
// string 单双引号都可以
let color: string = "blue"
color = 'red'
// 反引号可以包含多行 还可以使用${} 嵌入表达式。
let sentence: string = `Hello, my name is ${fullName}.
I'll be ${age + 1} years old next month.`;
// array 数组
let list : number[] = [1,2,3]
let list: Array<number> = [1,2,3]
// tuple 元组
// declare a tuple type
let x: [string, number];
// Initialize it
x = ["hello", 10]; // OK
// Initialize it incorrectly
x = [10, "hello"]; // Error