当前位置:网站首页>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.
边栏推荐
猜你喜欢
《如何戒掉坏习惯》读书笔记
代码 Revert 后再次 Merge 会丢失的问题,已解决
Multi-threaded ThreadPoolExecutor
Realization of vending machine function based on FPGA state machine
言简意赅,说说 @Transactional 在项目中的使用
多线程之ThreadPoolExecutor
Some work experience after joining the digital ic design
【DB运营管理/开发解决方案】上海道宁为您提供提高工作便利性的集成开发工具——Orange
Vulnhub靶机:GEMINI INC_ 2
学军中学推理社2017届招新试题
随机推荐
leetcode: 358. Reorder strings at K distance intervals
What does the sanction of the mixer Tornado mean for the DeFi market?
IDE compilation error: Dangling metacharacter
The ifconfig compared with IP command
Official release丨VS Code 1.70
IDE编译报错:Dangling metacharacter
Js prototype and prototype chain and prototype inheritance
Summary of debugging skills
shell脚本入门
入职数字ic设计后的一些工作心得
117. 本地开发好的 SAP UI5 应用部署到 ABAP 服务器时,中文字符变成乱码的原因分析和解决方案
Docker 链接sqlserver时出现en-us is an invalid culture错误解决方案
Add user error useradd: cannot open /etc/passwd
Mysql_Note3
【Pdf自动生成书签】
CC0 与商业 IP:哪种模式更适合 NFT?
PIFuHD配置记录
7 sorting algorithms that are often tested in interviews
小幻美图 API
深度学习中的模型设计