![](/img/trans.png)
[英]error TS2304: Cannot find name 'HeatmapOverlay' + angular 10
[英]Angular(6)'s Error TS2304: Cannot find name 'ICurrentWeatherData'
使用 Angular6 時發生錯誤,盡管我的應用程序可以運行並正常工作,但測試不會通過。 這是文件的代碼片段:
`import { Injectable } from '@angular/core'
import { HttpClient } from '@angular/common/http'
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'
import { environment } from '../../environments/environment'
import { ICurrentWeather } from '../interfaces'
@Injectable()
export class WeatherService {
constructor(private httpClient: HttpClient) {}
getCurrentWeather(city: string, country: string): Observable<ICurrentWeather> {
return this.httpClient
.get<ICurrentWeatherData>(
`${environment.baseUrl}api.openweathermap.org/data/2.5/weather?` +
`q=${city},${country}&appid=${environment.appId}`
)
.pipe(map(data => this.transformToICurrentWeather(data)))
}
private transformToICurrentWeather(data: ICurrentWeatherData): ICurrentWeather {
return {
city: data.name,
country: data.sys.country,
date: data.dt * 1000,
image: `http://openweathermap.org/img/w/${data.weather[0].icon}.png`,
temperature: this.convertKelvinToFahrenheit(data.main.temp),
description: data.weather[0].description,
}
}
private convertKelvinToFahrenheit(kelvin: number): number {
return (kelvin * 9) / 5 - 459.67
}
}`
src/app/weather/weather.service.ts(14,12) 中的錯誤:錯誤 TS2304:找不到名稱“ICurrentWeatherData”。
src/app/weather/weather.service.ts(21,44): 錯誤 TS2304: 找不到名稱“ICurrentWeatherData”。
您沒有導入 ICurrentWeatherData,在接口導入中我只看到 ICurrentWeather
當你替換這個時,你應該導入我認為有效的接口:
import { ICurrentWeather } from '../interfaces'
到 :
import { ICurrentWeather } from '../interfaces/ICurrentWeather'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.