TypeScript
Posted lianchenxi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TypeScript相关的知识,希望对你有一定的参考价值。
1.枚举emun
enum Sex //默认元素的下标从0开始递增(可指定) man = 1, woman = 2 let sex1: Sex = Sex.man; let sex2: Sex = Sex.woman;
console.log(sex1, sex2);
let man:string = Sex[1];
let woman:string = Sex[2];
console.log(man, woman);
//编译结果 var Sex; (function (Sex) Sex[Sex["man"] = 1] = "man"; Sex[Sex["woman"] = 2] = "woman"; )(Sex || (Sex = ));
var sex1 = Sex.man;
var sex2 = Sex.woman;
console.log(sex1, sex2); //1 2
var man = Sex[1];
var woman = Sex[2];
console.log(man, woman); //man woman
以上是关于TypeScript的主要内容,如果未能解决你的问题,请参考以下文章
TypeScriptTypeScript高级类型之Partial