当前位置:网站首页>Learn typescript (1)
Learn typescript (1)
2022-07-27 09:59:00 【InfoQ】
Why use typescript
- problem : Input and output parameter types of functions or methods , External conditions, etc
- Constraints of dynamic language : Manual debugging and other processes are required
- With Typescript: The code itself can answer the above questions
- Most errors can be found during compilation
- Put an end to some common mistakes
- Fully compatible with Javascript
- Third party libraries can write type files separately
- Most projects support typescipt
- Increased some learning costs
- Some development costs have been increased in the short term
data type
Raw data type
let isDone: boolean = false
let age: number = 10
let firstName: string = 'viking'
let message: string = `Hello, ${firstName}`
let u: undefined = undefined
let n:null = null
let num: number = undefined
Any type
let notSure: any = 4
notSure = 'maybe a string'
notSure = true
notSure.myName
notSure.getName()
Arrays and tuples
Array
let arr: number[] = [1,2,3]
arr.push(3)
// arguments An array of class IArguments type , No Array
function test(){
console.log(arguments);
arguments.length
arguments[0]
}
Tuples
let user: [string, number] = ['abc', 20]
user.push('1212') Can only push Existing types
Interface Interface
interface IPerson{
readonly id: number; // Read-only property
name: string
age: number
address?: string // Optional attribute
}
let lihua: IPerson = {
id: 1,
name: 'lihua',
age: 20
}
function
function add(x: number, y: number, z?: number): number {
if (typeof z === 'number') {
return x + y + z
} else {
return x + y
}
}
add(1, 2)
add(1, 2, 3)
const add = (x: number, y: number, z?: number): number => {
if (typeof z === 'number') {
return x + y + z
} else {
return x + y
}
}
interface ISum{
(x: number, y: number, z?: number):number
}
let add2: ISum = add边栏推荐
- 好久不送书,浑身不舒服
- Understand chisel language. 25. Advanced input signal processing of chisel (I) -- asynchronous input and de jitter
- [cloud native • Devops] master the container management tool rancher
- Exercises --- quick arrangement, merging, floating point number dichotomy
- July training (day 17) - breadth first search
- 深度剖析分库分表最强辅助Sharding Sphere
- 3D修复论文:Shape Inpainting using 3D Generative Adversarial Network and Recurrent Convolutional Networks
- PCL的ICP配准示例
- Oracle RAC 19C PDB instance is down
- Final examination paper of engineering materials
猜你喜欢

找工作 4 个月, 面试 15 家,拿到 3 个 offer

3D修复论文:Shape Inpainting using 3D Generative Adversarial Network and Recurrent Convolutional Networks

S switch stacking scheme configuration guide

Summary of binary tree exercises

How to use tdengine sink connector?

3D restoration paper: shape painting using 3D generative advantageous networks and recurrent revolutionary networks

c'mon! Please don't ask me about ribbon's architecture principle during the interview

吃透Chisel语言.24.Chisel时序电路(四)——Chisel内存(Memory)详解

Sentinel ten thousand word tutorial | book delivery at the end of the text

吃透Chisel语言.27.Chisel进阶之有限状态机(一)——基本有限状态机(Moore机)
随机推荐
flash闪存使用和STM32CUBEMX安装教程【第三天】
When I went to oppo for an interview, I got numb
活体检测综述
超赞的卡尔曼滤波详解文章
达梦 PARTGROUPDEF是自定义的对象吗?
Provincial Emergency Management Department: Guangzhou can strive to promote the experience of emergency safety education for children
二叉树习题总结
吃透Chisel语言.27.Chisel进阶之有限状态机(一)——基本有限状态机(Moore机)
StyleGAN论文笔记+修改代码尝试3D点云生成
S switch stacking scheme configuration guide
LeetCode.565. 数组嵌套____暴力dfs->剪枝dfs->原地修改
[scm] source code management - lock of perforce branch
Towards the peak of life
Talk about 10 scenarios of index failure. It's too stupid
Understand chisel language. 22. Chisel sequential circuit (II) -- detailed explanation of chisel counter: counter, timer and pulse width modulation
It's great to write code for 32 inch curved screen display! Send another one!
Understand chisel language. 27. Chisel advanced finite state machine (I) -- basic finite state machine (Moore machine)
Review of in vivo detection
吃透Chisel语言.25.Chisel进阶之输入信号处理(一)——异步输入与去抖动
I grabbed a ticket and thought I found the system bug of 12306