[英]How to use same technique as ts omit, but applying it to object of concrete types?
我基本上想实现 left | 查看它们的类型的两个对象的右连接。 例如, object默认类型 RequestInit 的配置。
config = {
headers: {
'Content-Type': 'application/json',
},
}
我有一个自定义类型的customConfig ,例如,包含其他查询参数的 CustomRequestInit,稍后我将加入 url。
customConfig = {
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
params: {
'tk': '2edr3q2afa3',
}
}
这个 object 具有来自 RequestInit class 的属性,它们应该覆盖配置object 中的相同属性。来自customConfig的其他属性不得在最终配置object 中。我如何通过它们的类型离开加入这两个对象,省略 CustomRequestInit 带来的额外键?
你想要达到的目标有点不清楚。
此类型从 B 添加 A 中缺少的属性(仅添加新属性)。
type AddMissing<A, B> = A & Omit<B, keyof A>;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.