当前位置:网站首页>typescript的type
typescript的type
2022-06-26 06:13: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}
边栏推荐
猜你喜欢
随机推荐
TCP connection and disconnection, detailed explanation of state transition diagram
Data visualization practice: Experimental Report
低代码实时数仓构建系统的设计与实践
On site commissioning - final method of kb4474419 for win7 x64 installation and vs2017 flash back
numpy. tile()
视图简析
Unsatisfied dependency expressed through field ‘baseMapper‘; nested exceptio
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
Web components series (10) -- realize the basic layout of mycard
numpy. random. choice
zip(*arg)的用法
Architecture design method
PyTorch使用多GPU并行训练及其原理和注意事项
Thinking and summary of technical ability
Comparison between Prometheus and ZABBIX
如何设计好的技术方案
Matching environment of ES6
Efk upgrade to Clickhouse log storage practice
Lamda expression
Application of cow read / write replication mechanism in Linux, redis and file systems