当前位置:网站首页>TS 泛型的extends属性
TS 泛型的extends属性
2022-06-09 09:15:00 【你还差的远呢。】
T extends object 是泛型约束的一种表现。
泛型约束简单点来说就是把泛型的具体化数据类型范围缩小
理解 T extends object:
extends表示具体的泛型类型只能是 object 类型, 某个变量如果能断言成 object类型[变量 as object ] , 那么这个变量的类型符合 T extends object 。
就是说该变量的类型可以是T的具体化类型


限制了泛型的类型,我们传了 number 就会报错
tip: 我们使用了 T extends object,传什么具体的泛型不会报错呢?
我们传的具体的泛型 能断言成 extends 后面的类型
也就是我们的具体的泛型 可以是 extends 后面的类型, 或者是extends 后面的类型的子集
class Container<T extends object>{
t!: T
show(): T {
console.log(this.t);
return this.t
}
}
let c = new Container<{
}>()
let c = new Container<object>()
边栏推荐
- 【线性代数】理解正定矩阵和半正定矩阵
- 微信小程序之获取用户基本信息
- 2022-2028 global mobile phone jammer industry research and trend analysis report
- Judge whether it is JSON or file stream
- Countdown 3 days 𞓜 sofachannel 28 sofaark class isolation framework design
- Wechat applet obtains user information and updates it
- MySQL basic addition, deletion, modification and query exercise
- [redis learning 13] redis builds master-slave cluster, sentinel cluster and partition cluster
- MySQL基础 DML与DDL学习
- - Bean method ‘redisConnectionFactory‘ in ‘JedisConnectionConfiguration‘ not loaded because @Conditi
猜你喜欢

【线性代数】理解特征值和特征向量

Solve the apscheduler error: run time of job... Next run at:...) "was missed by
![Esp32 learning notes [WiFi network] - 01ap & sta](/img/04/de14412d6244ec120c587d98f103aa.png)
Esp32 learning notes [WiFi network] - 01ap & sta

MySQL基础 数据类型精讲

Implementation of WTM based on NETCORE framework

FreeRTOS semaphore review

ERP system, compilation and learning

Error deleting environment variable path

How do you view the multi runtime architecture of dapr and layotto?

Omit 应用 减少 TS 重复代码
随机推荐
Esp32 learning notes [WiFi network] - 01ap & sta
Wechat applet to obtain basic user information
微信小程序之获取用户基本信息
[code comment] Doxygen
Cypher usage statement record of neo4j
Android 开发面试心得总结,实录整理(必看)
MySQL basic knowledge
2022-2028 global technology monitoring countermeasures industry research and trend analysis report
Write InputStream to file write multipartfile to file
LeetCode_回溯_困难_301. 删除无效的括号
2022-2028 global natural volcanic ash industry research and trend analysis report
【1数据采集】数据爬虫的完整学习路径
Android common principle interview questions (preliminary sorting)~
解决apscheduler报错:Run time of job …… next run at: ……)” was missed by
MySQL basic DML and DDL learning
three. JS learning notes (XV) -- shader pattern
【线性代数】理解正定矩阵和半正定矩阵
Judge whether it is JSON or file stream
Creation of menu for wechat applet development
Dotnet core can also coordinate distributed transactions!