当前位置:网站首页>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";
边栏推荐
- Leetcode daily question (1870. minimum speed to arrive on time)
- After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.
- UWA Pipeline 2.2.1 版本更新说明
- What does UDP attack mean? UDP attack prevention measures
- LeetCode Algorithm 2181. 合并零之间的节点
- 详解SQL中Groupings Sets 语句的功能和底层实现逻辑
- 3. Business and load balancing of high architecture
- [some special grammars about C]
- ROS learning_ Basics
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models. common‘ from ‘/home/yolov5/models/comm
猜你喜欢
因高额网络费用,Arbitrum 奥德赛活动暂停,Nitro 发行迫在眉睫
详解SQL中Groupings Sets 语句的功能和底层实现逻辑
26岁从财务转行软件测试,4年沉淀我已经是25k的测开工程师...
Short video, more and more boring?
Machine learning plant leaf recognition
Visitor tweets about how you can layout the metauniverse
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用Shap值对XGBoost模型实现可解释性案例之详细攻略
kubernetes集群搭建Zabbix监控平台
[server data recovery] case of offline data recovery of two hard disks of IBM server RAID5
Development of entity developer database application
随机推荐
Is it difficult for girls to learn software testing? The threshold for entry is low, and learning is relatively simple
Leetcode daily question (1870. minimum speed to arrive on time)
Prefix and array series
Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
【刷题】怎么样才能正确的迎接面试?
Every API has its foundation when a building rises from the ground
Automated test environment configuration
[advanced software testing step 1] basic knowledge of automated testing
首发织梦百度推送插件全自动收录优化seo收录模块
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
UniPro甘特图“初体验”:关注细节背后的多场景探索
What is the difference between int (1) and int (10)? Senior developers can't tell!
软件测试外包到底要不要去?三年真实外包感受告诉你
19. Actual memory management of segment page combination
Missing monitoring: ZABBIX monitors the status of Eureka instance
Basic commands of MySQL
The psychological process from autojs to ice fox intelligent assistance
UWA Pipeline 2.2.1 版本更新说明
kubernetes集群搭建Zabbix监控平台
这个高颜值的开源第三方网易云音乐播放器你值得拥有