rcp.RequestHeaders申明如下:
export type RequestHeaders = {
[k: string]: string | string[] | undefined;
'authorization'?: string;
'accept'?: ContentType | ContentType[];
'accept-charset'?: string | string[];
'accept-encoding'?: ContentCoding | ContentCoding[];
'accept-language'?: string | string[];
'cache-control'?: string | string[];
'cookie'?: string | string[];
'range'?: string | string[];
'upgrade'?: string | string[];
'user-agent'?: string;
'content-type'?: ContentType;
};
现在有两个header需要合并:
let defaultHeader: rcp.RequestHeaders = {
'x-weimai-origin': 'doc-hm',
'accept': 'application/json'
}
let newHeader: rcp.RequestHeaders = {
'x-weimai-version': '1.0',
'user-agent': 'WMAPP/6.76.0'
}
如何合并这四个属性都有的?ts常用的解构赋值不支持。Partial也不支持type。
{
...defaultHeader,
...newHeader
}
参考示例: