当前位置:网站首页>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
}
边栏推荐
- IDEA全局搜索快捷键(ctrl+shift+F)失效修复
- cmake 基本使用过程
- In hot summer, please put away this safe gas use guide!
- Opencv learning notes 5 -- document scanning +ocr character recognition
- [dynamic programming] p1004 grid access (four-dimensional DP template question)
- 2022-2-15 learning xiangniuke project - Section 4 business management
- The first word of JVM -- detailed introduction to JVM and analysis of runtime data area
- 使用net core 6 c# 的 NPOI 包,讀取excel..xlsx單元格內的圖片,並存儲到指定服務器
- 三十之前一定要明白的职场潜规则
- 建立自己的网站(14)
猜你喜欢

The first word of JVM -- detailed introduction to JVM and analysis of runtime data area

关于重载运算符的再整理

opencv学习笔记六--图像拼接

Problem note - Oracle 11g uninstall

Minimum spanning tree and bipartite graph in graph theory (acwing template)
![[15. Interval consolidation]](/img/6c/afc46a0e0d14127d2c234ed9a9d03b.png)
[15. Interval consolidation]
![[Verilog quick start of Niuke question series] ~ use functions to realize data size conversion](/img/e1/d35e1d382e0e945849010941b219d3.png)
[Verilog quick start of Niuke question series] ~ use functions to realize data size conversion

IDEA全局搜索快捷键(ctrl+shift+F)失效修复

Rearrangement of overloaded operators
![[Verilog quick start of Niuke series] ~ multi function data processor, calculate the difference between two numbers, use generate... For statement to simplify the code, and use sub modules to realize](/img/30/aea4ae24f418eb971bca77a1d46bef.png)
[Verilog quick start of Niuke series] ~ multi function data processor, calculate the difference between two numbers, use generate... For statement to simplify the code, and use sub modules to realize
随机推荐
从零开发小程序和公众号【第三期】
tensorflow2-savedmodel convert to tflite
Salesforce、约翰霍普金斯、哥大 | ProGen2: 探索蛋白语言模型的边界
The markdown editor uses basic syntax
idea中新建的XML文件变成普通文件的解决方法.
Solid basic basic grammar and definition function
项目中字符串判空总结
These three online PS tools should be tried
tensorflow2-savedmodel convert to tflite
Rearrangement of overloaded operators
【LeetCode】16、最接近的三数之和
问题随记 —— Oracle 11g 卸载
Mongodb second call -- implementation of mongodb high availability cluster
生成随机数(4位、6位)
Build your own website (14)
2022-2-15 learning xiangniuke project - Section 4 business management
Opencv learning notes 5 -- document scanning +ocr character recognition
适合没口才的人做,加入中视频伙伴计划收益是真香,一个视频拿3份收益
【15. 区间合并】
Pat 1065 a+b and C (64bit) (20 points) (16 points)