美文网首页
1.typescript基础类型

1.typescript基础类型

作者: 我的昵称好听吗 | 来源:发表于2019-01-06 12:03 被阅读0次

    官网: https://www.tslang.cn/docs/handbook/basic-types.html

    • 1.字符串:string
    • 2.浮点类型,数字:number
    • 3.布尔值:boolean
    • 4.数组:Array<number> || number[] || ReadonlyArray<number> (只读数组)
    • 5.元组:[number,string] tuple
    • 6.枚举:enum
    • 7.任何类型:any
    • 8.没有任何类型:void
    • 9.Null 和 Undefined
    • 10.非原始类型:object
      1. never
    // string 
    let name1: string = 'hahahha';
    console.log(name1); //hahahha
    
    // number 
    let name2: number = 30;
    console.log(name2);//30
    
    // boolean 
    let name3: boolean = true;
    console.log(name3);//true
    
    // array 
    let name4: number[] = [2];
    let name5: Array<String> = ['2'];
    console.log(name4);//[2]
    console.log(name5);//['2']
    let nameArr: ReadonlyArray<number> = [2];
    nameArr[1] = 3; // Index signature in type 'ReadonlyArray<number>' only permits reading.
     
    // 元组 tuple 
    let name6: [number,string,object,boolean];
    name6 = [3,'3',{},true];
    console.log(name6);
    
    // enum
    enum List{One =2,Two=4};
    let name7: List = List.One;
    let ListName: string = List[4];
    console.log(name7);
    console.log(ListName);
    
    // any
    let name8: any = 'sdf';
    console.log(name8);
    name8 = 34;
    console.log(name8);
    let na:number | undefined;
    na = undefined;
    
    // void 
    function myvoid ():void{
        console.log('void');
    }
    myvoid();
    let myvoidtype: void = null;
    console.log(myvoidtype);
    myvoidtype = undefined;
    console.log(myvoidtype);
    
    // null && undefined
    let name9:null = null;
    let name10: undefined = undefined;
    console.log(name9);
    console.log(name10);
    
    // object
    let name11: object = {};
    console.log(name11); 
    

    相关文章

      网友评论

          本文标题:1.typescript基础类型

          本文链接:https://www.haomeiwen.com/subject/noqsrqtx.html