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

Gof23 - abstract factory pattern

Introduction to canal deployment, principle and use

Deeply uncover Ali (ant financial) technical interview process with preliminary preparation and learning direction

GoF23—建造者模式

Underlying principle of MySQL index

Redis multithreading and ACL

How to select and build a real-time data warehouse scheme

University Information Management System

Install pyinstaller

Zotero文献管理工具之Jasminum(茉莉花)插件
随机推荐
[spark] how to implement spark SQL field blood relationship
消息队列-功能、性能、运维对比
01 golang and matlab code of knapsack problem
低代码实时数仓构建系统的设计与实践
Soft power and hard power in program development
Keepalived to achieve high service availability
06. talk about the difference and coding between -is and = = again
Gof23 - factory mode
Ppt template crawler case
视图简析
Gof23 - prototype mode
04. basic data type - list, tuple
MYSQL索引不生效的原因
Lamda expression
TCP連接與斷開,狀態遷移圖詳解
事务与消息语义
Logstash——Logstash向Email发送告警邮件
On site commissioning - final method of kb4474419 for win7 x64 installation and vs2017 flash back
Five solutions across domains
The purpose of writing programs is to solve problems