Using typescript, Angular 6+ and rxjs, how to best represent to the caller that an HTTP response content is empty (Content-Length=0)?
Without specifying types in the method call (get
, post
, etc.), an Observable<Object>
is returned, which is misleading regarding the response content, as one can be tempted to use the given object:
let response: Observable<Object> = httpClient.post('...');
response.subscribe(o => ...);
In this case, o
is always null, but this is not explicit nor checked by the compiler.
A better solution would be to return Observable<null>
but I find the semantic to be ambiguous, as null could also refer to a null data (eg, a customer without phone number would have a phoneNumber property set to null).