当前位置:网站首页>TS Basics
TS Basics
2022-07-06 07:01:00 【Wang Zhao has no king】
notes :TS In the syntax , No embellishments , You're going to report a mistake
This article just introduces TS Basic syntax , It will be updated later TS Deep content
1、 Boolean type
Modifier :boolean :Boolean
var time:boolean = true;// Qualifier shorthand
time = new boolean(true);// This format is in TS An error is reported in Chinese grammar
var time3:Boolean = false;// Qualifier capitalization
time3 = new Boolean(true);// No error in words
2、 value type
Modifier :number :Number
var time:number = 1;
var times:Number = 2;
times = new Number(3);
3、 String type
Modifier :string :String
var time:string = "abc";
var times:String = "abcdd";
4、 Undefined type
Modifier :undefined
var b:undefined = undefined;
5、 Or the use can be number It can also be undefined
var time:number|undefined;
time = 12;
time = undefined;
6、 function
function time(a: number, b? number, c: number = 1):number {
return 12;
}
// There will be no error in the following two
// Don't use default values
// time(1, 2, 3)
// Use the default value
time(1,2);
b?number Equate to number|undefined
c:number = 1; The default value is
function time():number :number Is the type of return value
function time():void :void There is no return value
7、 An array type
7.1、 One dimensional array
var time:Array<number> = [1, 2, 3, 4]; // It can only be of numerical type
var time:Array<number|string> = [1 , 2, 3, "a"]; // It can be a numeric type , It can also be a string type
7.2、 Two dimensional array
var time:Array<Array<number|string>> = [
[1, 2, "a" ],
[1, 2, "a" ]
]
8、 A tuple type
// Types must be in the same order as values
var time:[number, string, boolean] = [1, "a", true];
9、 Enumeration type
Similar to the object , Its value is like a constant , Once defined, it cannot be changed , Equivalent to using the freezing method in the object
enum COLOR{RED, GREEN, PINK};
console.log(COLOR.RED,COLOR.PINK); // 0,2
enum COLOR{RED="red", GREEN="green", PINK="pink"};
console.log(COLOR.RED, COLOR.PINK); // red, pink
10、null type
var time:null = null;
11、any Any type
Don't know what type to give , Set to any type
However, it is not allowed to use any type No use !!!
because TS It is originally a restricted type , You use the any It's all of any type , that TS It's useless .
var vb:any = 1;
vb = "a";
边栏推荐
- Briefly describe the differences between indexes, primary keys, unique indexes, and joint indexes in mysql, and how they affect the performance of the database (in terms of reading and writing)
- 19.段页结合的实际内存管理
- 前缀和数组系列
- Successfully solved typeerror: data type 'category' not understood
- [some special grammars about C]
- 中青看点阅读新闻
- Fedora/rehl installation semanage
- Apache dolphin scheduler source code analysis (super detailed)
- C language_ Double create, pre insert, post insert, traverse, delete
- Zhongqing reading news
猜你喜欢
Every API has its foundation when a building rises from the ground
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Monotonic stack
云上有AI,让地球科学研究更省力
Pallet management in SAP SD delivery process
Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation
Database basics exercise part 2
When my colleague went to the bathroom, I helped my product sister easily complete the BI data product and got a milk tea reward
NFT on fingertips | evaluate ambire on G2, and have the opportunity to obtain limited edition collections
随机推荐
RichView TRVStyle 模板样式的设置与使用
C语言_双创建、前插,尾插,遍历,删除
Latex文字加颜色的三种办法
医疗软件检测机构怎么找,一航软件测评是专家
ROS2安装及基础知识介绍
Librosa audio processing tutorial
基于PyTorch和Fast RCNN快速实现目标识别
Database basics exercise part 2
前缀和数组系列
leetcode6109. 知道秘密的人数(中等,周赛)
Reflex WMS medium level series 3: display shipped replaceable groups
19.段页结合的实际内存管理
kubernetes集群搭建Zabbix监控平台
Map of mL: Based on the adult census income two classification prediction data set (whether the predicted annual income exceeds 50K), use the map value to realize the interpretable case of xgboost mod
leetcode841. 钥匙和房间(中等)
Setting and using richview trvstyle template style
微信脑力比拼答题小程序_支持流量主带最新题库文件
Machine learning plant leaf recognition
Chapter 7 - thread pool of shared model
BUU的MISC(不定时更新)