当前位置:网站首页>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
}
边栏推荐
- DirectX修复工具V4.1公测![通俗易懂]
- DirectX repair tool v4.1 public beta! [easy to understand]
- tensorflow2-savedmodel convert to pb(frozen_graph)
- Some thoughts on software testing
- NPDP产品经理国际认证报名有什么要求?
- 购物商城6.27待完成
- Opencv Learning Notes 6 -- image feature [harris+sift]+ feature matching
- Solid smart contract development - easy to get started
- Mongodb second talk - - mongodb High available Cluster Implementation
- 问题随记 —— Oracle 11g 卸载
猜你喜欢
问题随记 —— Oracle 11g 卸载
音乐播放器开发实例(可毕设)
微服务开发步骤(nacos)
Opencv interpolation mode
Written on the first day after Doris graduated
C#学习笔记(5)类和继承
The first word of JVM -- detailed introduction to JVM and analysis of runtime data area
Music player development example (can be set up)
Official announcement: Apache Doris graduated successfully and became the top project of ASF!
Task.Run(), Task.Factory.StartNew() 和 New Task() 的行为不一致分析
随机推荐
C learning notes (5) class and inheritance
TypeScript: let
微服务追踪SQL(支持Isto管控下的gorm查询追踪)
[zero basic IOT pwn] reproduce Netgear wnap320 rce
Opencv learning notes 5 -- document scanning +ocr character recognition
opencv学习笔记五--文件扫描+OCR文字识别
solidty-基础篇-结构体和数组,私有 / 公共函数,函数的返回值和修饰符,事件
【14. 区间和(离散化)】
The first word of JVM -- detailed introduction to JVM and analysis of runtime data area
Don't want to knock the code? Here comes the chance
项目中字符串判空总结
Pat 1065 a+b and C (64bit) (20 points) (16 points)
[zero basic IOT pwn] reproduce Netgear wnap320 rce
qt捕获界面为图片或label显示
Some thoughts on software testing
保证生产安全!广州要求危化品企业“不安全不生产、不变通”
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é
JVM第二话 -- JVM内存模型以及垃圾回收
[dynamic programming] p1004 grid access (four-dimensional DP template question)
[getting started with Django] 13 page Association MySQL "multi" field table (check)