当前位置:网站首页>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}边栏推荐
猜你喜欢

TCP连接与断开,状态迁移图详解

EFK昇級到ClickHouse的日志存儲實戰

Message queue - function, performance, operation and maintenance comparison

【Spark】Spark SQL 字段血缘如何实现

Zotero文献管理工具之Jasminum(茉莉花)插件

Prometheus和Zabbix的对比

MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications

Pytorch uses multi GPU parallel training and its principle and precautions

Mysql-10 (key)

数据可视化实战:实验报告
随机推荐
SQL server functions
Gof23 - factory mode
Print bit information of numbers
ts中枚举类型(enum)简单使用
MySQL-08
The difference between overload method and override method
The interviewer with ByteDance threw me an interview question and said that if I could answer it, other companies would have an 80% chance of passing the technical level
numpy. frombuffer()
Redis多线程与ACL
Thinking skills of technical leaders
01 golang and matlab code of knapsack problem
消息队列-消息事务管理对比
DPDK——TCP/UDP协议栈服务端实现(一)
NPM private server problem of peanut shell intranet penetration mapping
Gof23 - builder mode
Data visualization practice: Experimental Report
typescript的type
Installing rainbow in various kubernetes with Helm
numpy. random. choice
Matching environment of ES6