当前位置:网站首页>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')
边栏推荐
- Promouvoir le développement de l'industrie culturelle et touristique par la recherche, l'apprentissage et l'enseignement pratique du tourisme
- Duchefa丨P1001植物琼脂中英文说明书
- Abnova DNA marker high quality control test program
- Viewrootimpl and windowmanagerservice notes
- Chemical properties and application instructions of prosci Lag3 antibody
- 概率论机器学习的先验知识(上)
- Duchefa p1001 plant agar Chinese and English instructions
- 实现浏览页面时校验用户是否已经完成登录的功能
- Graph embedding learning notes
- How to renew NPDP? Here comes the operation guide!
猜你喜欢

The development of research tourism practical education helps the development of cultural tourism industry

Clion-MinGW编译后的exe文件添加ico图标

Analysis of steam education mode under the integration of five Education

leetcode:1139. 最大的以 1 为边界的正方形

Duchefa low melting point agarose PPC Chinese and English instructions
![最长摆动序列[贪心练习]](/img/e1/70dc21b924232c7e5e3da023a4bed2.png)
最长摆动序列[贪心练习]

ProSci LAG3抗体的化学性质和应用说明

Talk about my fate with some programming languages

XML建模

Enclosed please find. Net Maui's latest learning resources
随机推荐
php中explode函数存在的陷阱
Abnova丨DNA 标记高质量控制测试方案
使用WebAssembly在浏览器端操作Excel
Is the securities account given by the school of Finance and business safe? Can I open an account?
ODPS 下一个map / reduce 准备
leetcode:1139. 最大的以 1 为边界的正方形
大二下个人发展小结
Mode - "Richter replacement principle"
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
基於flask寫一個接口
Abnova total RNA Purification Kit for cultured cells Chinese and English instructions
Duchefa p1001 plant agar Chinese and English instructions
LeetCode: Distinct Subsequences [115]
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
Binary search
水泥胶黏剂BS 476-4 不燃性测试
PHP反序列化+MD5碰撞
解析创客教育的知识迁移和分享精神
ts 之 类的简介、构造函数和它的this、继承、抽象类、接口
Abnova CD81 monoclonal antibody related parameters and Applications