当前位置:网站首页>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.
边栏推荐
- Idea (优选)cherry-pick操作
- ES进阶 数组功能语法新特性详解
- (Nips-2015)空间变换器网络
- YTU 2418: C语言习题 矩阵元素变换
- 全局大喇叭--广播机制
- 21天学习挑战赛第一周总结
- postgresql ilike create function
- JS-DOM元素对象
- Summary of debugging skills
- 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
猜你喜欢
OpenCV founder: Open source must not be completely free!
[BX] and loop
《如何戒掉坏习惯》读书笔记
BUU刷题记录
The problem that Merge will be lost again after code Revert has been solved
多线程之ThreadPoolExecutor
DOM-DOM树,一个DOM树有三种类型的节点
Deep Learning - Second Time
添加用户报错useradd: cannot open /etc/passwd
Summary of debugging skills
随机推荐
Docker 链接sqlserver时出现en-us is an invalid culture错误解决方案
CC0 与商业 IP:哪种模式更适合 NFT?
DOM-DOM tree, a DOM tree has three types of nodes
调试技巧总结
The 125th day of starting a business - a note
YTU 2411: 谁去参加竞赛?【简单循环】
MySQL的主从复制+读写分离+分库分表,看这一篇文章就够了
【DB运营管理/开发解决方案】上海道宁为您提供提高工作便利性的集成开发工具——Orange
今天聊聊接口幂等性校验
Official release丨VS Code 1.70
数论基础-整除(编程例题)
How to solve the problem of Tomcat booting and crashing
"How to kick a bad habit to read notes?
对加密世界的经济误解:现金是储蓄?稀缺性创造价值?
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
The ifconfig compared with IP command
21 Day Learning Challenge Week 1 Summary
"Beijing-Taiwan high-speed rail" debuted on Baidu map, can it really be built in 2035?
夫妻一方婚内向异性大额转款,怎么判
redis学习五redis的持久化RDB,fork,copyonwrite,AOF,RDB&AOF混合使用