I am trying to get the data from an API endpoint using the following block of code.
interface IResponse{
"id": number,
"title": string,
"description": string,
"price": number,
"discountPercentage": number,
"rating": number,
"stock": number,
"brand": string,
"category": string,
"thumbnail": string,
"images": Set<string>
}
fetch('https://dummyjson.com/products/1')
.then(res => res.json())
.then(res => {
let b: IResponse = res;
console.log(b)
});
As you can see, the type of images
in IResponse
is a set of strings. However, the API response returns an array of images, and I am assigning that response object to a variable with type IResponse. So the question is, why doesn't typescript complain about type mismatch of images property in response object(array) and IResponse
interface (set of Strings) upon assignment?