I'm using TypeScript 2.5.2. I have tried downgrading to TypeScript 2.2.2, which the same code has worked on another project.
**Error: file: Weather.tsx' severity: 'Error' message: 'Argument of type '(response: IListItem) => void' is not assignable to parameter of type '(value: { weather: IListItem; }) => void | PromiseLike'. Types of parameters 'response' and 'value' are incompatible.
Type '{ weather: IListItem; }' has no properties in common with type 'IListItem'.'**
What is wrong with the syntax?
Source code on GitHub
From just looking at these types and not the rest of the code: the type parameter in
.then((response: HttpClientResponse): Promise<{weather: IListItem}>
specifies that the response is an object with aweather
property of typeIListItem
rather than the bareIListItem
you expect at.then((response: IListItem): void => {
, which explains the type error.If the api response is indeed an object, you can change the latter to
.then((response: {weather: IListItem})
and add.weather
to each appearance ofresponse
in the body (or even simply destructure without a type annotation:then(({weather}): void => {
and useweather
instead ofresponse
.)On the other hand, if the api just returns an
IListItem
, you can change the former to.then((response: HttpClientResponse): Promise<IListItem> => {
.