'How to deal with http response type in angular?
I write a http get request:
getProduct(path, opts?): Observable<Product> {
return this.http.get(path, opts?.httpParams).pipe(
map((res:IProduct) => new Product(res))
);
}
My Product class construct with a Interface:
export Interface IProduct {
productName:string;
productCode:string;
descr:string;
}
I thought when I assign a interface as type in map() , it will have a check about the content of the response. If it miss some property it will give me a error or something. But it doesn't, It just pass everything to try to instance a Product Object.
Am I missunderstanding about the usage of Interface? How can I ensure the response match the Interface or not?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
