当前位置:网站首页>TS报错 Don‘t use `object` as a type. The `object` type is currently hard to use
TS报错 Don‘t use `object` as a type. The `object` type is currently hard to use
2022-07-01 14:55:00 【小火车况且况且】
TS报错 Don’t use object as a type. The object type is currently hard to use
问题来源
function func<T extends object, S extends object>() {
}
当使用泛型继承object属性时, typescript就会提示问题
Don't use `object` as a type. The `object` type is currently hard to use ([see this issue](https://github.com/microsoft/TypeScript/issues/21732)).
Consider using `Record<string, unknown>` instead, as it allows you to more easily inspect and use the keys @typescript-eslint/ban-types
问题来源可以查看提示的issue的链接https://github.com/microsoft/TypeScript/issues/21732
其实解决办法也可以查看typescript的提示, 通过Record<string, unknown>替换object
function func<T extends Record<string, unknown>, S extends Record<string, unknown>>() {
}
拓展-Record 链接
Record是typescript内置的高级类型
- 主要用途为了定义对象的
key和value类型, 用来显示对象键的类型和值的类型
使用方法, 定义对象a的键是string类型, 值是string | number的联合类型
const a: Record<string, string | number> = {
'name': '小火车',
'age': 18
}
边栏推荐
- 榨汁机UL982测试项目有哪些
- Buuctf reinforcement question ezsql
- Opencv learning notes 5 -- document scanning +ocr character recognition
- Quelle valeur le pdnp peut - il apporter aux gestionnaires de produits? Vous savez tout?
- The first word of JVM -- detailed introduction to JVM and analysis of runtime data area
- [leetcode] 16. The sum of the nearest three numbers
- [leetcode 324] 摆动排序 II 思维+排序
- tensorflow2-savedmodel convert to pb(frozen_graph)
- opencv学习笔记六--图像特征[harris+SIFT]+特征匹配
- 【LeetCode】16、最接近的三数之和
猜你喜欢
![After twists and turns, I finally found the method of SRC vulnerability mining [recommended collection]](/img/ac/ab6053e6ea449beedf434d4cf07dbb.png)
After twists and turns, I finally found the method of SRC vulnerability mining [recommended collection]

首届技术播客月开播在即

一波三折,终于找到src漏洞挖掘的方法了【建议收藏】

One of the first steps to redis

Basic operations of SQL database

Don't want to knock the code? Here comes the chance

Microservice development steps (Nacos)

Opencv interpolation mode

【14. 区间和(离散化)】

Music player development example (can be set up)
随机推荐
Summary of empty string judgment in the project
Basic operations of SQL database
[leetcode 324] 摆动排序 II 思维+排序
【15. 区间合并】
22-06-26周总结
APK签名原理
JVM second conversation -- JVM memory model and garbage collection
炎炎夏日,这份安全用气指南请街坊们收好!
[leetcode] 16. The sum of the nearest three numbers
Yyds dry goods inventory hcie security day13: firewall dual machine hot standby experiment (I) firewall direct deployment, uplink and downlink connection switches
DirectX修复工具V4.1公测![通俗易懂]
What is the relationship between network speed, broadband, bandwidth and traffic?
What data capabilities do data product managers need to master?
Generate random numbers (4-bit, 6-bit)
Build your own website (14)
The data in the database table recursively forms a closed-loop data. How can we get these data
C learning notes (5) class and inheritance
网速、宽带、带宽、流量三者之间的关系是什么?
榨汁机UL982测试项目有哪些
Day-02 database