• typescript数据类型


    // 布尔类型
    let isDone: boolean = false;
    // 数字类型 所有数字都是浮点数 number
    let decLiteral: number = 6;
    let hexLiteral: number = 0xf00d;
    let binaryLiteral: number = 0b1010;
    let octalLiteral: number = 0o744;
    // 字符串
    let username: string = "bob";
    username = "smith";
    //  可以使用模版字符 定义多行文本和内嵌表达式
    let uname: string = "gene";
    let age: number = 37;
    let sentence: string =
      "hello, my name is ${name} I'll be ${age+1} years old next month.";
    
    // 数组  元素类型后接上[]
    let list: number[] = [1, 2, 3];
    let list1: Array<number> = [1, 2, 3];
    
    // 元组
    let x: [string, number];
    x = ["hello", 10];
    console.log(x[0].substr(1));
    
    //枚举
    enum Color {
      Red,
      Green,
      Blue
    }
    let c: Color = Color.Green;
    
    //任意值
    let notSure: any = 4;
    notSure = "maybe a string instead";
    notSure = false;
    
    notSure.ifItExists();
    notSure.toFixed();
    
    // 空值 没有任何类型
    function warnUser(): void {
      alert("This is my warning message");
    }
    let unusable: void = undefined;
    // null undefined
    let u: undefined = undefined;
    let n: null = null;
    
    // Never 永不存在的值类型
    function error(message: string): never {
      throw new Error(message);
    }
    
    function fail() {
      return console.error("something failed ");
    }
    
    //Object 表示非原始类型 除 number,sting, boolean, symbol, null underfined之外的类型
    declare function create(o: object|null):void;
    
    create({prop:0});
    create(null);
    

      

  • 相关阅读:
    javaScript控制按钮可用/不可用
    查询信息时对数据进行分页显示
    css样式-记录没记住的样式
    js里cookie,localStorage的简单用法
    关于BaseServlet的使用
    Web项目运行时tomcat服务器启动失败
    关于form表单提交数据后不跳转页面+ajax接收返回值的处理
    网页的标题栏添加小图标
    memcache安装过程
    Got minus one from a read call
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/9429188.html
Copyright © 2020-2023  润新知