当前位置:网站首页>Typescript study notes | Byte Youth Training Notes
Typescript study notes | Byte Youth Training Notes
2022-08-11 02:57:00 【. admiration】
Introduction to TypeScript
TypeScript is a free and open source programming language *developed by Microsoft*.It is a superset of JavaScript, and in essence TypeScript extends JavaScript syntax, which means that it supports all JavaScript syntax.TS adds type support on top of JavaScript and can be run anywhere JavaScript is running.
TypeScript It is a *static type checker* that checks the program for errors before execution (compiles), can display labelsUnexpected behavior in the code, and checking based on the kind of value, reduces the likelihood of errors.
TypeScript Features:
- Enhanced readability: parsing TSDos based on syntax, enhanced ide
- Enhanced maintainability: exposed most errors at compile stage.(In large-scale projects with multi-person cooperation, better stability and development efficiency are obtained)
- Included in compatible with all JS features, support coexistence
- Support progressive introduction and upgrade
Object Type
Features: Object types are more refined in TS, and each object has its own type language.
**Interface**: In object-oriented programming, an interface is a normative definition, which defines the specification of behavior and actions. In programming, the interface acts as a restrictionand normative role.
> **NOTE**: Defining an interface with the interface keyword generally capitalizes the first letter and prefixes the interface name with a capital I.
- **optional attribute**: define that this attribute may not exist.(Add a ? sign after the attribute).
- **Read-only properties**: Constraint properties cannot be assigned outside of object initialization.(Add the keyword **readonly** before one or some properties of the object, you can set the property to be read-only).
- **Any Attribute**: Constraints that all object attributes must be subtypes of this attribute.
###Array type
**Two ways**:
```1.const numbers: number[] = [a,b,c]2.const strings: Array = ['a', 'b', 'c']```
What if there are both numbers and strings in the array?
**Union type (a type composed of two or more other types, which can be any of these types)**:
```const arr: (number | string)[] = [1,'a',2,'b']```
Function Type
In TypeScript, there are two common ways to define functions - Function Declaration and Function Expression.
1. Specify parameters individually, return value type:
// The first and second numbers add numeric types to the parameters num1 and num2 respectively, and the third number add numeric types to the return valuefunction plus(num1: number, num2: number): number {return num1+ num2}plus(1,2)
1. Specify parameters individually, return value type:
```const add = (num1: number, num2: number): number => {return num1 + num2}add(2,3)```
**NOTE**: Do not confuse `=>` in TypeScript with `=>` in ES6.
- In the type definition of TypeScript, `=>` is used to represent the definition of the function, **the left side is the input type, which needs to be enclosed in parentheses, and the right side is the output type**.
- In ES6, `=>` is called arrow function, which is widely used.
边栏推荐
- 117. 本地开发好的 SAP UI5 应用部署到 ABAP 服务器时,中文字符变成乱码的原因分析和解决方案
- ①In-depth analysis of CAS SSO single sign-on framework source code
- [idea error] Invalid target distribution: 17 solution reference
- DOM-DOM tree, a DOM tree has three types of nodes
- comp3331-9331-21t2-midterm复习
- The ifconfig compared with IP command
- leetcode: 358. Reorder strings at K distance intervals
- The practice of alibaba data synchronization component canal
- 正式发布丨VS Code 1.70
- 解决vim与外界的复制粘贴(不用安装插件)
猜你喜欢
Summary of Logstash log data write exception troubleshooting
入职数字ic设计后的一些工作心得
Logstash日志数据写入异常排查问题总结
OpenCV founder: Open source must not be completely free!
CSAPP Data Lab
Idea (preferred) cherry-pick operation
Js prototype and prototype chain and prototype inheritance
Realization of vending machine function based on FPGA state machine
如何解决高度塌陷
WeChat public account background management
随机推荐
Research on the Application of Privacy Computing Fusion
一言(ヒトコト)Hitokoto API
CSDN 博客更换皮肤
HPSO and multi-core LSSVM based network intrusion detection
"How to kick a bad habit to read notes?
Some work experience after joining the digital ic design
leetcode:358. K 距离间隔重排字符串
正式发布丨VS Code 1.70
comp3331-9331-21t2-midterm复习
四大组件---ContentResolver
Vulnhub靶机:GEMINI INC_ 2
①In-depth analysis of CAS SSO single sign-on framework source code
BUU brushing record
广州纸质发票再见!开住宿费电子发票即将全面取代酒店餐饮加油站发票
超声图像三维拼接-可视化选择,总体思路
网络安全笔记第四天day4(kali基本操作)
The negative semantic transformation layer
GBJ3510-ASEMI家电电源用整流桥GBJ3510
成都纸质发票再见!开住宿费电子发票即将全面取代酒店餐饮加油站发票
Entity to Vo conversion