当前位置:网站首页>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
}
边栏推荐
- Official announcement: Apache Doris graduated successfully and became the top project of ASF!
- Task.Run(), Task.Factory.StartNew() 和 New Task() 的行为不一致分析
- DirectX修复工具V4.1公测![通俗易懂]
- Opencv mat class
- Ubuntu 14.04下搭建MySQL主从服务器
- En utilisant le paquet npoi de net Core 6 c #, lisez Excel.. Image dans la cellule xlsx et stockée sur le serveur spécifié
- 241. Design priorities for operational expressions
- [leetcode 324] swing sorting II thinking + sorting
- 关于软件测试的一些思考
- Demand prioritization method based on value quantification
猜你喜欢
Rearrangement of overloaded operators
微服务追踪SQL(支持Isto管控下的gorm查询追踪)
JVM第一话 -- JVM入门详解以及运行时数据区分析
写在Doris毕业后的第一天
[零基础学IoT Pwn] 复现Netgear WNAP320 RCE
cmake 基本使用过程
241. Design priorities for operational expressions
JVM second conversation -- JVM memory model and garbage collection
Microservice development steps (Nacos)
JVM第二话 -- JVM内存模型以及垃圾回收
随机推荐
The data in the database table recursively forms a closed-loop data. How can we get these data
After twists and turns, I finally found the method of SRC vulnerability mining [recommended collection]
[leetcode] 16. The sum of the nearest three numbers
Guess lantern riddles, not programmers still can't understand?
Task. Run(), Task. Factory. Analysis of behavior inconsistency between startnew() and new task()
从零开发小程序和公众号【第三期】
Take you to API development by hand
Opencv learning notes 5 -- document scanning +ocr character recognition
Solid basic basic grammar and definition function
Basic operation of database
JVM第二话 -- JVM内存模型以及垃圾回收
数字化转型:数据可视化赋能销售管理
The State Administration of Chia Tai market supervision, the national development and Reform Commission and the China Securities Regulatory Commission jointly reminded and warned some iron ores
TypeScript: let
Day-02 database
Detailed explanation of ArrayList expansion, expansion principle [easy to understand]
What if you are always bullied because you are too honest in the workplace?
241. Design priorities for operational expressions
What value can NPDP bring to product managers? Do you know everything?
What data capabilities do data product managers need to master?