• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

typescript数据类型

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
// 布尔类型
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);

  


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
在Sublime2/3中使用build命令编译TypeScript文件发布时间:2022-07-18
下一篇:
typescript中高级类型之交叉类型与联合类型发布时间:2022-07-18
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap