I am seeking to utilize the fromObject
property of HttpParamsOptions
in order to convert a custom object into a params-object.
Here is an example where it works:
foo(): void {
const testObject = {
id: 123;
name: 'test';
someExample: 'test';
}
const httpParams = new HttpParams({ fromObject: testObject });
...
}
However, in this scenario it does not work:
export interface SearchParams {
id: number;
name: string;
someExample: string;
}
foo(testObject: SearchParams): void {
const httpParams = new HttpParams({ fromObject: testObject });
...
}
The issue arises when I define the object type using fromObject
.
Error: TS2322: Type 'SearchParams' is not assignable to type '{ [param: string]: string | number | boolean | readonly (string | number | boolean)[]; }'. Index signature is missing in type 'SearchParams'.
Do you have any suggestions on how to resolve this? I am working with Angular 12.