2017-09-21 2 views
0

저는 TypeScript 2.5.2를 사용하고 있습니다. 다른 프로젝트에서 동일한 코드가 작동하는 TypeScript 2.2.2로 다운 그레이드를 시도했습니다.TypeScript 오류는 만족하지 않습니다

이 ** 오류 : 파일 : Weather.tsx ' 심각도'오류 '메시지 : '유형의 인자 '(대응 : IListItem) => 공극이'타입 의 파라미터에 할당되지 않은 경우 (값 : {weather : IListItem;}) => void | PromiseLike '. 'response'및 'value'매개 변수 유형이 호환되지 않습니다.

유형 '{날씨 : IListItem; } '은'IListItem '유형과 공통된 속성이 없습니다. **

구문에 어떤 문제가 있습니까? .then((response: HttpClientResponse): Promise<{weather: IListItem}>의 형식 매개 변수는 응답 유형 IListItemweather 속성 객체임을 지정 : GitHub

VSCode Screenshot

답변

2

에서에

소스 코드는 코드의 나머지 부분을 이러한 유형의보고하지 벌크 IListItem보다는 .then((response: IListItem): void => {으로 예상됩니다. 오류 유형을 설명합니다. API 응답 객체가 참이면

, 당신은 .then((response: {weather: IListItem})에 후자를 변경하고 몸에 response의 각 모양에 .weather를 추가 (또는 단순히 유형 약어없이 destructure도 : then(({weather}): void => {response 대신 weather를 사용합니다.) 수

한편, API가 IListItem을 반환하는 경우 이전을 .then((response: HttpClientResponse): Promise<IListItem> => {으로 변경할 수 있습니다.

+0

.then ((response : HttpClientResponse) : Promise ) 제 해결책입니다. – JoshYates1980

+0

비슷한 문제가 있습니다. 오류의 원인을 알고 계십니까? : https://github.com/CodeHeight/some- webparts/issues/1 – JoshYates1980

+0

SO 질문으로 게시하면 다른 사람들도 이동 가능합니다 :-) – Oblosys

관련 문제