I am seeking clarification on how to utilize the object type for sending headers, aside from HttpHeaders provided in the HTTPClient declaration.
While working with Angular HttpClient, I aim to include headers using an Object. However, I am unsure of how to define an object of type [header: string]: string | string[];. I need assistance understanding this object declaration, as I am encountering a similar issue with HttpParams. My code snippet is as follows:
getLoggedInUser(requestHeaderParam: GetLoggedInUserHeaderRequestParam): Observable<LoggedInUserResponse> {
return this.http.get<LoggedInUserResponse>(`${environment.apiBaseUrl}/auth/loggedInUser`, { headers: requestHeaderParam });
}
The error message displayed in VS Code is as follows:
[ts] Argument of type '{ headers: GetLoggedInUserHeaderRequestParam; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'. Types of property 'headers' are incompatible. Type 'GetLoggedInUserHeaderRequestParam' is not assignable to type 'HttpHeaders | { [header: string]: string | string[]; }'. Type 'GetLoggedInUserHeaderRequestParam' is not assignable to type '{ [header: string]: string | string[]; }'. Index signature is missing in type 'GetLoggedInUserHeaderRequestParam'.
The Request Param type is defined as below:
export interface GetLoggedInUserHeaderRequestParam {
uid: string;
PSID?: string;
}
The HttpClient Declaration is outlined as below:
HttpClient.get(url: string, options: {
headers?: HttpHeaders | {
[header: string]: string | string[];
};
observe?: "body";
params?: HttpParams | {
[param: string]: string | string[];
};
reportProgress?: boolean;
responseType: "arraybuffer";
withCredentials?: boolean;
}): Observable<ArrayBuffer>
Your guidance is greatly appreciated!
Note: My query pertains to utilizing the Object directly, specifically in relation to its declaration type { [header: string]: string | string[]; } within the HttpClient context.