In my Angular 7 application, I have defined the following interface:
export interface Request {
limit?: number;
offset?: number;
}
Additionally, there is a service method implemented like so:
public get(request: Request): Observable<Response>> {
const parameters = { 'limit': String(request.limit), 'offset': String(request.offset) };
return this.httpClient.get<Response>>(`projects`, { params: parameters });
}
When calling the service from a component, I have the following snippet:
let request: Request = { offset: 20 };
projectService.get(request)
However, the API response shows the error message:
The value 'undefined' is not valid for Limit.
It seems like I need to assign null
to the limit
property when it is not explicitly provided in the request. How can I ensure that undefined
values are automatically set to null
instead of remaining undefined
?