当前位置:网站首页>typescript的type
typescript的type
2022-06-26 06:18:00 【前端一枚】
type的常用寫法:
//未使用type
let sum:(x:number,y:number) => number
sum=(x,y)=>x+y
const result = sum(1,2)
console.log(result)
//使用type
type PlusType=(x:number,y:number)=>number
let sum2:PlusType=(x,y)=>x+y
const result2=sum2(2,3)
console.log(result2)
// type結合聯合類型
type strOrNum=string|number
let result3:strOrNum='12'
result3=12
//比較常用
type Directions='Up'|'Down'|'Left'|'Right'
let toWhere:Directions='Down'
//type結合接口
interface IName{name:string}
type IPerson=IName&{age:number}
let person:IPerson={name:'jim',age:123}
边栏推荐
- Logstash -- send an alert message to the nail using the throttle filter
- 工作积累——Web请求中使用ThreadLocal遇见的问题
- Logstash - logstash sends an alarm email to email
- Tortoise and rabbit race example
- GoF23—原型模式
- Introduction to canal deployment, principle and use
- 获取当前月份的第一天和最后一天,上个月的第一天和最后一天
- Application of cow read / write replication mechanism in Linux, redis and file systems
- Several promotion routines of data governance
- Customer Stories | Netease spring breeze: the "spring breeze" of the fun industry, reaching out to all areas through in-depth interaction
猜你喜欢
GoF23—工厂模式
100 cases of go language
MySQL-08
New generation engineers teach you how to play with alluxio + ml (Part 1)
Install pyinstaller
How to design a good technical scheme
Connexion et déconnexion TCP, détails du diagramme de migration de l'état
Ppt template crawler case
Architecture design method
Import export simple
随机推荐
Vs2022 offline installation package download and activation
04. basic data type - list, tuple
numpy.exp()
Efk Upgrade to clickhouse log Storage Reality
numpy. log
The sysdig 2022 cloud native security and usage report found that more than 75% of the running containers have serious vulnerabilities
MySQL-06
消息队列-消息事务管理对比
视图简析
Introduction to canal deployment, principle and use
SQL server functions
PyTorch混合精度原理及如何开启该方法
Tencent WXG internship experience (has offered), I hope it will help you!
numpy. frombuffer()
Zotero文献管理工具之Jasminum(茉莉花)插件
3.pyinstaller模块介绍
实时数仓方案如何选型和构建
GoF23—原型模式
Five solutions across domains
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could