当前位置:网站首页>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.
边栏推荐
- 对加密世界的经济误解:现金是储蓄?稀缺性创造价值?
- 基于FPGA状态机的自动售货机功能实现
- (Nips-2015)空间变换器网络
- Logstash日志数据写入异常排查问题总结
- MySQL的主从复制+读写分离+分库分表,看这一篇文章就够了
- Future Trends in Vulnerability Management Programs
- (CVPR - 2017) in depth and potential body learning context awareness feature for pedestrian recognition
- Economic Misunderstandings in the Crypto World: Is Cash a Savings?Scarcity creates value?
- ES6进阶 字符串处理新特性
- 《人生若如初见》命运多舛,人物饱满,朱亚文角色反差太惊喜
猜你喜欢

【idea 报错】 无效的目标发行版:17 的解决参考

Google search skills - programmer is recommended

Multi-threaded ThreadPoolExecutor

代码 Revert 后再次 Merge 会丢失的问题,已解决

CSDN 博客更换皮肤

Future Trends in Vulnerability Management Programs

ARM development (4) How to read the chip manual for novice Xiaobai, bare metal driver development steps and pure assembly to achieve lighting, assembly combined with c lighting, c to achieve lighting

最倒霉与最幸运

ESP32的环境配置(arduino arduino2.0 VScode platform哪个好用?)

Js prototype and prototype chain and prototype inheritance
随机推荐
DOM树的遍历-----修改样式,选择元素,创建和删除节点
压力能变成动力
df和df -lh的意思
Future Trends in Vulnerability Management Programs
CC0 与商业 IP:哪种模式更适合 NFT?
CC0 vs. commercial IP: which model is better for NFTs?
qtcreator调试webkit
否定语义转化层
comp3331-9331-21t1-midterm复习
超声图像三维拼接-可视化选择,总体思路
数论基础-整除(编程例题)
网络安全笔记第四天day4(kali基本操作)
(CVPR-2017)在身体和潜在部位学习深度上下文感知特征以进行行人重识别
21 Day Learning Challenge Week 1 Summary
Idea (优选)cherry-pick操作
Vim and copy and paste from the outside (don't need to install the plugin)
ES6进阶 字符串处理新特性
DOM-DOM树,一个DOM树有三种类型的节点
[Pdf generated automatically bookmarks]
21天学习挑战赛第一周总结