该类HttpResponse<T>
确实没有任何_embedded
属性。这就是你得到编译器错误的原因,因为 Typescript 静态地键入了你的响应HttpResponse<Object>
(泛型类型参数用于body
响应的属性)。
在这种情况下,将响应投射到<any>
似乎是一个可行的解决方案,如果您知道随时期待_embedded
那里的道具。不过,空检查可能是一个不错的补充。
这是HttpResponse<T>
供参考的打字:
/**
* A full HTTP response, including a typed response body (which may be `null`
* if one was not returned).
*
* `HttpResponse` is a `HttpEvent` available on the response event
* stream.
*
* @experimental
*/
export declare class HttpResponse<T> extends HttpResponseBase {
/**
* The response body, or `null` if one was not returned.
*/
readonly body: T | null;
/**
* Construct a new `HttpResponse`.
*/
constructor(init?: {
body?: T | null;
headers?: HttpHeaders;
status?: number;
statusText?: string;
url?: string;
});
readonly type: HttpEventType.Response;
clone(): HttpResponse<T>;
clone(update: {
headers?: HttpHeaders;
status?: number;
statusText?: string;
url?: string;
}): HttpResponse<T>;
clone<V>(update: {
body?: V | null;
headers?: HttpHeaders;
status?: number;
statusText?: string;
url?: string;
}): HttpResponse<V>;
}