当前位置:网站首页>Generics of TS
Generics of TS
2022-07-05 20:57:00 【qq_ forty-six million three hundred and two thousand two hundre】
Basic use of generics
// Not clear name Used when the type of
// The representation defines a generic T, Then pass on the reference name yes T type ,myFun The return value of T type ; When myFun It can only be determined when called T Value
function myFun<T>(name: T): T {
return name
}
myFun<string>('hellow')//T by string type
myFun<number>(15)//T by number type
Generics can specify multiple
function myFun<T, K>(name: T, age: K): T{
return name
}
myFun<string, number>('tt', 18)//T by string type ,K by number type
Generic binding interface
interface Inter{
length: number
}
//T extends Inter For generics T Must be Inter Subclasses of
function myFum<T extends Inter>(value: T): number{
return value.length
}
myFum('abc')//'abc'.length String has length attribute , accord with Inter The interface specification
myFum([1,3,9,5,])//[1,3,9,5,].length Array has length attribute , accord with Inter The interface specification
myFum({
length: 5})//{length: 5}.length The object has length attribute , accord with Inter The interface specification
Generic binding class
class myClass<T>{
name: T
constructor(name: T){
this.name = name
}
}
const my = new myClass<string>('tm')
边栏推荐
- Abnova CD81 monoclonal antibody related parameters and Applications
- Abnova cyclosporin a monoclonal antibody and its research tools
- 实现浏览页面时校验用户是否已经完成登录的功能
- 中国的软件公司为什么做不出产品?00后抛弃互联网;B站开源的高性能API网关组件|码农周刊VIP会员专属邮件周报 Vol.097
- Sophomore personal development summary
- Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
- Abnova丨 MaxPab 小鼠源多克隆抗体解决方案
- Abnova maxpab mouse derived polyclonal antibody solution
- 研学旅游实践教育的开展助力文旅产业发展
- 研學旅遊實踐教育的開展助力文旅產業發展
猜你喜欢

Abnova CRISPR spcas9 polyclonal antibody protocol

CLion配置visual studio(msvc)和JOM多核编译

Influence of oscilloscope probe on measurement bandwidth

线程池的使用

木板ISO 5660-1 热量释放速率摸底测试

MySQL InnoDB架构原理

Abnova fluorescent dye 620-m streptavidin scheme

Abnova e (diii) (WNV) recombinant protein Chinese and English instructions

Pytorch实战——MNIST数据集手写数字识别

Abnova丨DNA 标记高质量控制测试方案
随机推荐
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
Determine the best implementation of horizontal and vertical screens
实现浏览页面时校验用户是否已经完成登录的功能
LeetCode: Distinct Subsequences [115]
使用WebAssembly在浏览器端操作Excel
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
2. < tag hash table, string> supplement: Sword finger offer 50 The first character DBC that appears only once
Monorepo管理方法论和依赖安全
浅聊我和一些编程语言的缘分
水泥胶黏剂BS 476-4 不燃性测试
Monorepo management methodology and dependency security
Implementation of redis unique ID generator
培养机器人教育创造力的前沿科技
Analysis of steam education mode under the integration of five Education
AITM2-0002 12s或60s垂直燃烧试验
Abnova丨E (DIII) (WNV) 重组蛋白 中英文说明书
Abnova blood total nucleic acid purification kit pre installed relevant instructions
【案例】元素的显示与隐藏的运用--元素遮罩
判断横竖屏的最佳实现
ts 之 泛型