blog icon indicating copy to clipboard operation
blog copied to clipboard

typescript基本用法

Open wuxianqiang opened this issue 5 years ago • 0 comments

约束基本数据类型

let title:string = '张三'
let age:number = 18
let loading:boolean = true
let obj:null = null
let total:undefined = undefined

联合类型,多种数据类型中的一种

let title:number|string = 18

引用数据类型,数组,有两种写法

let arr1:number[] = [1,2,3]
let arr2:Array<number> = [1,2,3]

对象:也就是除number,string,boolean,symbol,null或undefined之外的类型。

let obj:object = [1,2,3]

约束实例上的属性

class Menu {
  currentTime: string;
  constructor () {
    this.currentTime = 'hello'
  }
}

// 换种写法
class Menu {
  currentTime: string = 'hello';
}

wuxianqiang avatar Nov 21 '19 02:11 wuxianqiang