当前位置:网站首页>Typescript notes
Typescript notes
2022-07-26 23:23:00 【Xi Xin o】
// Typescript install 、 compile
// In the use of npm Before the command Must install node.js
// install
npm install -g typescript
cnpm install -g typescript
yarn -g add typescript
// function
tsc helloworld.ts
node helloworld.js
// install yarn And cnpm
npm install -g yarn
npm install -g cnpm
// Typescript development tool Vscode Automatic compilation .ts file
1. tsc --int Generate configuration files tsconfig.json
2. modify tsconfig.json, Open notes outDir: './js'
3. choice terminal -> Run the task -> tsc: monitor -tsconfig.json Then you can automatically monitor the code dynamically
typescript data type :
boolean Boolean type
number Numeric type
string String type
array An array type
tuple A tuple type
enum Enumeration type
any Any type
null
undefined
void Empty type
never
// Function declaration method :
function func ():string{
// sting Specify the type returned by the function
return '123123'
}
// Anonymous functions
const func = function ():number {
}
// Functions with parameters
function func (name: string, age: number): string {
return `${
name}-${
number}`
}
// Functions that do not return values No, return Function of
function func ():void {
}
// Function with optional arguments ( Optional parameters must be configured after mandatory parameters )
function func (name:string,age?:number):string {
return ' Optional parameter function ' // name Must pass parameters ,age Transmissible parameters
}
// Default parameter function
function func (name: string, age:number=30):string{
retun ' Return string ' // age Set default parameters
}
// Three point operator Receive the value of the new parameter
function func (...arg:number[]):number{
// arg = [1,2,3,4]
return ' Returns the number type ' // The expansion operator receives the remaining parameters
}
func(1,2,3,4)
function func(arg1:number, arg2:number, ...arg3:number[]):number{
return ' Returns the number type ' // arg1=1, arg2=2, arg3=[3,4,5,6]
}
func(1,2,3,4,5,6)
// function overloading
java Overload of methods in : Overloading refers to two or more functions with the same name , But they have different parameters , In this case, there will be overloading of functions
typescript Heavy load in , Try the purpose of multiple functions by providing multiple function type definitions for the same function .
// es5 A method with the same name appears , The following will replace the above method
function func (name;string):string
function func (age:number):string
function func (str:any):any{
if (typeof str==='string') {
return `${
str}-- name `
} else {
return `${
str}-- Age `
}
}
// Inside the arrow function this Point to context
边栏推荐
- MySQL random paging to get non duplicate data
- 关于 StatefulWidget,你不得不知道的原理和要点!
- org.yaml.snakeyaml.scanner. ScannerException: mapping values are not allowed here in ‘reader‘, line
- Weilai cup 2022 Niuke summer multi school training camp 2
- MySQL syntax uses detailed code version
- 面试官问:JS的this指向
- Openstack virtual machine network card is renamed cirename0
- Introduction to the use of Jerry downloader forced download tool_ Ac695n696nad14ad15 full range support
- kalibr标定realsenseD435i --多相机标定
- Professor Ashe, a Chinese scientist, made a positive response to the suspected fake Nature paper
猜你喜欢

Import of MySQL data
![[untitled]](/img/88/68952146da17a4a504ee7d1bc8858d.png)
[untitled]

Lesson 2 of Silicon Valley classroom - building project environment and developing lecturer management interface

你知道磁环电感的常见磁芯类型有哪些吗?

kalibr标定realsenseD435i --多相机标定

Hcia-r & s self use notes (23) DHCP

org.yaml.snakeyaml.scanner. ScannerException: mapping values are not allowed here in ‘reader‘, line

HCIA-R&S自用笔记(23)DHCP

Regular expressions and bypass case recurrence

Recruit | PostgreSQL database R & D engineers every week, with an annual salary of 60+, high salary for famous enterprises, and challenge yourself!
随机推荐
New employees of black maredge takeout
8-其他编程语言--记录
SQL Basics
Learn various details and thoughts of chatroom implementation in Muduo
Cheaper than seals, with a large space for shape explosion. Is there really no match for 200000 or so? Chang'an's new "King fried" is cost-effective
How to recover the original data when the U disk is damaged, and how to recover the damaged data when the U disk is damaged
sql多表查询的练习
Siliwei's counterattack: huiding's under screen optical fingerprint patent involved in the case was declared invalid
企业数据治理面临的六大挑战!
A13 processor has become the biggest highlight of iphone11 series: its performance is twice that of Kirin 980!
App information reconnaissance & night God simulator burp packet capture configuration
org.yaml.snakeyaml.scanner. ScannerException: mapping values are not allowed here in ‘reader‘, line
Recruit | PostgreSQL database R & D engineers every week, with an annual salary of 60+, high salary for famous enterprises, and challenge yourself!
The secret weapon of apple iphone11 series: U1 chip may usher in the era of ultra wideband
Openstack virtual machine network card is renamed cirename0
Huawei conspires to acquire Brazilian operators?
基于gRPC编写golang简单C2远控
ESMFold: AlphaFold2之后蛋白质结构预测的新突破
程序员成长第二十九篇:如何激励员工?
沟通中经常用到的几个库存术语