I want to use the fromObject key of HttpParamsOptions to cast an custom object into a params-object.
This works:
foo(): void {
const testObject = {
id: 123;
name: 'test';
someExample: 'test';
}
const httpParams = new HttpParams({ fromObject: testObject });
...
}
This doesn't work:
export interface SearchParams {
id: number;
name: string;
someExample: string;
}
foo(testObject: SearchParams): void {
const httpParams = new HttpParams({ fromObject: testObject });
...
}
fromObject does not work if I define the object type.
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'.
Any ideas how to solve this? I'm using Angular 12.
HttpParamstakes a parameter with an index signature.